欢迎来到天天文库
浏览记录
ID:16742886
大小:106.00 KB
页数:24页
时间:2018-08-24
《java 基础 30题 __答案》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、1、从键盘输入一个正整数,按数字的相反顺序输出。packagecom.my.ccit;importjava.util.Scanner;publicclassa1{publicstaticvoidmain(String[]args){Scanners=newScanner(System.in);intm=s.nextInt();intsum=0;intn;while(m!=0){n=m%10;m=m/10;sum=sum*10+n;}System.out.println(sum);}}2、写一条for语句,计数条件为n从100~200,步长为2;然后再用while语句实现同样的
2、循环。packagecom.my.ccit;publicclassa2{publicstaticvoidmain(String[]args){intn;for(n=100;n<=200;n=n+2){System.out.println(n);}}otherstaffoftheCentre.Duringthewar,ZhuwastransferredbacktoJiangxi,andDirectorofthenewOfficeinJingdezhen,JiangxiCommitteeSecretary.Startingin1939servedasrecorderoftheWe
3、stNorthOrganization,SecretaryoftheSpecialCommitteeAfterthevictoryofthelongMarch,hehasbeentheNorthwestOfficeoftheFederationofStateenterprisesMinister,ShenmufuguSARmissions,DirectorofNingxiaCountypartyCommitteeSecretaryandrecorderoftheCountypartyCommitteeSecretary,Ministersand}3、编写一段程序,运行时向用户
4、提问“你考了多少分?(0~100)”,接受输入后判断其等级并显示出来。判断依据如下:等级={优(90~100分);良(80~89分);中(60~69分);差(0~59分);}packagecom.my.ccit;importjava.util.Scanner;publicclassa3{publicstaticvoidmain(String[]args){Scanners=newScanner(System.in);intm=s.nextInt();if(m>=90&&m<=100){System.out.println("优");}elseif(m>=80){System.
5、out.println("良");}elseif(m>=70){System.out.println("中");}elseif(m>=60){System.out.println("及格");}else{System.out.println("差");}}}4、使用for循环语句求出1~100之间的质数。packagecom.my.ccit;publicclassa4{/***@paramargs*/publicstaticvoidmain(String[]args){//TODOAuto-generatedmethodotherstaffoftheCentre.During
6、thewar,ZhuwastransferredbacktoJiangxi,andDirectorofthenewOfficeinJingdezhen,JiangxiCommitteeSecretary.Startingin1939servedasrecorderoftheWestNorthOrganization,SecretaryoftheSpecialCommitteeAfterthevictoryofthelongMarch,hehasbeentheNorthwestOfficeoftheFederationofStateenterprisesMinister,She
7、nmufuguSARmissions,DirectorofNingxiaCountypartyCommitteeSecretaryandrecorderoftheCountypartyCommitteeSecretary,Ministersandstub4、使用for循环语句求出1~100之间的质数。intn;intj;booleanflag=false;for(n=1;n<=100;n++){for(j=2;j<=n-1;j++){if(n%j==0){flag=false;break;}else{f
此文档下载收益归作者所有