您好,欢迎访问三七文档
第二章Java语法基础1、下列表达式是否有错?若有错,请说明何处出现何种错误;若无错,请给出其值。(1)3+42^-8-28(2)362*4&488/4+20(3)abc+123||82出现错误,||为逻辑运算符。(4)2*4&&02||4%2出现错误,&&和||为逻辑运算符。2、任意准备一份学生成绩表,其中包括至少3门课程、每门课程至少10名同学的成绩。请编写程序完成以下功能:(1)统计并输出各门课程的平均成绩。(2)输出等级表:优、良、中、及格与不及格。publicclassChengjibiao{publicstaticvoidmain(String[]args){inta,b,i=0,j=0;floatbujige=0,jige=0,zhong=0,liang=0,you=0;doubleaverage;intabc[][]={{74,47,88},{46,87,90},{82,56,60},{72,80,65},{92,91,89},{76,83,87},{87,76,70},{78,85,72},{54,92,67},{100,90,80}};for(j=0;j3;j++){System.out.println(第+(j+1)+位同学:);for(i=1;i11;i++){if(abc[i-1][j]60){System.out.print(不及格);bujige=bujige+1;}elseif(abc[i-1][j]70){System.out.print(及格);jige=jige+1;}elseif(abc[i-1][j]80){System.out.print(中);zhong=zhong+1;}elseif(abc[i-1][j]90){System.out.print(良);liang=liang+1;}else{System.out.print(优);you=you+1;}}System.out.print(\n);}System.out.print(\n);for(i=1;i4;i++){System.out.print(第+i+门功课的平均成绩:);average=0;for(j=0;j10;j++){average+=abc[j][i-1];}System.out.println(average/10);}}}3、编写程序,用数组存储并输出乘法九九表。publicclass99{publicstaticvoidmain(String[]args){int[]a={1,2,3,4,5,6,7,8,9};for(inti:a){for(intj=1;j=i;j++){System.out.print(j);System.out.print(*);System.out.print(i);System.out.print(=);System.out.print(i*j);System.out.print();}}System.out.println();}}4、有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第三个月后每个月又生一对兔子,假如兔子都不死,问每个月的兔子总数为多少?publicclassRabit{publicstaticfinalintMONTH=20;publicstaticvoidmain(String[]args){longf1=1L,f2=1L;longf;for(inti=3;iMONTH;i++){f=f2;f2=f1+f2;f1=f;System.out.print(第+i+个月的兔子对数:+f2+\n);}}5、打印出所有的水仙花数,所谓水仙花数是指一个三位数,其各位数字立方和等于该数本身。例如:153是一个水仙花数,因为153=1的三次方+5的三次方+3的三次方。publicclassThirdNarcissusNum{staticintb,bb,bbb;publicstaticvoidmain(String[]args){for(intnum=101;num1000;num++){ThirdNarcissusNumtnn=newThirdNarcissusNum();tnn.f(num);}}publicvoidf(intm){bbb=m/100;bb=(m%100)/10;b=(m%100)%10;if((bbb*bbb*bbb+bb*bb*bb+b*b*b)==m){System.out.println(m);}}}
本文标题:java-作业二
链接地址:https://www.777doc.com/doc-4882422 .html