资源描述:
《java基础语法部分测试题》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、www.tjitcast.comJAVA基础语法部分测试题编程题:1.判断2008年是闰年还是平年.闰年的条件:能被4整除且不能被100整除的数,或者能被400整除的数.答;publicclassYear{publicstaticvoidmain(String[]args){inta=2008;if(a%4==0&a%100!=0){System.out.println(“2008年为闰年”);}elseif(a%400==0){System.out.println(“2008年为闰年”);}else{System
2、.out.println(“2008年为平年”);}}}2.用循环的方式输出九九乘法表,如下:1*1=11*2=22*2=31*3=32*3=63*3=9...1*9=92*9=183*9=274*9=365*9=456*9=547*9=638*9=729*9=81答:publicclassTest2{publicstaticvoidmain(String[]args){for(inti=1;i<10;i++){for(intj=1;j<10;j++){if(j>i)//三角形乘法表,换行判断{System.out
3、.println("");continue;}System.out.print(""+i+"*"+j+"="+i*j);}otherstaffoftheCentre.Duringthewar,ZhuwastransferredbacktoJiangxi,andDirectorofthenewOfficeinJingdezhen,JiangxiCommitteeSecretary.Startingin1939servedasrecorderoftheWestNorthOrganization,Secretaryoft
4、heSpecialCommitteeAfterthevictoryofthelongMarch,hehasbeentheNorthwestOfficeoftheFederationofStateenterprisesMinister,ShenmufuguSARmissions,DirectorofNingxiaCountypartyCommitteeSecretaryandrecorderoftheCountypartyCommitteeSecretary,Ministersandwww.tjitcast.com}
5、}}3.接收键盘输入的数据,判断60以上的,70以上的,80以上的数据分别出现的个数.答:importjava.util.*;publicclassTest3{publicstaticvoidmain(String[]args){Scannerinput=newscanner(System.in);intsum=input.nextInt();inta=0;intb=0;intc=0;if(sum>=60){a++;}System.out.println(“大于60的个数为”+a);if(sum>=70){b++;
6、}System.out.println(“大于70的个数为”+b);if(sum>=80){c++;}System.out.println(“大于80的个数为”+c);}}4.分别用三种不同的循环方式,实现1到10的总和.………………省略号第一种.for(inti=0;i<=10;i++){i+=i;}第二种While(i<=10){i+=i;i++;}第三种do{i+=ii++;}while(i<=10);5.输出1-100所有的偶数?并计算偶数和?publicclassTest5{publicstaticvoi
7、dmain(String[]args){intj=0;for(inti=1;i<=100;i++){if(i%2==0){System.out.println(i);otherstaffoftheCentre.Duringthewar,ZhuwastransferredbacktoJiangxi,andDirectorofthenewOfficeinJingdezhen,JiangxiCommitteeSecretary.Startingin1939servedasrecorderoftheWestNorthOrg
8、anization,SecretaryoftheSpecialCommitteeAfterthevictoryofthelongMarch,hehasbeentheNorthwestOfficeoftheFederationofStateenterprisesMinister,ShenmufuguSARmissions,DirectorofNingxiaCo