资源描述:
《耿祥义张跃平 java大学实用教程-编程题答案》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、习题解答第一章作业题1.publicclassHello{publicstaticvoidmain(Stringargs[]){System.out.pintln(“早上好,goodMorning”);}}2.importjava.applet.*;importjava.awt.*;publicclassBoyextendsApplet{publicvoidpaint(Graphicsg){g.setColor(Color.blue);g.drawString("你好,hello",12,30);}}第二章作业题1.publ
2、icclassZuoYe2_1{publicstaticvoidmain(Stringargs[]){charc='а';System.out.println("字母"+c+"在unicode表中的顺序位置:"+(int)c);System.out.println("字母表:");while(c<='я'){System.out.print(""+c);c=(char)(c+1);}}}2.importjava.util.*;publicclassZuoYe2_2{publicstaticvoidmain(Stringarg
3、s[]){Scannerreader=newScanner(System.in);longchengji=1;intm=0;while(reader.hasNextInt()){intx=reader.nextInt();m=m+1;chengji=chengji*x;}System.out.println(m+"个数的乘积为"+chengji);}}第三章作业题1.importjava.util.*;publicclassZuoYe3_1{publicstaticvoidmain(Stringargs[]){Scanner
4、reader=newScanner(System.in);doubley=0,x=0;x=reader.nextDouble();if(x<0)y=-1+2*x;elseif(x==0)y=-1;elseif(x>0)y=-1+3*x;System.out.println(y);}}2.publicclassZuoYe3_2{publicstaticvoidmain(Stringargs[]){intsum=0,m=3,n=7,a=1;while(a<=1000){if(a%m==0&&a%n==0)sum=sum+a;a+
5、+;}System.out.println("sum="+sum);}}3.publicclassZuoYe3_3{publicstaticvoidmain(Stringargs[]){longsum=0,a=8,item=a,n=10,i=1;for(i=1;i<=n;i++){sum=sum+item;item=item*10+a;}System.out.println(sum);}}4.publicclassZuoYe3_4{publicstaticvoidmain(Stringargs[]){doublesum=0,
6、a=1,b=1,fuhao=1,item=a/b;inti=1;while(i<=1000){sum=sum+fuhao*item;i++;fuhao=fuhao*(-1);b=b+2;item=a/b;}System.out.println("sum="+sum);}}5.publicclassZuoYe3_5{publicstaticvoidmain(Stringargs[]){doublesum=0,a=1;inti=1;while(i<=20){if(i>=10)sum=sum+a;i++;a=a*i;}System
7、.out.println("sum="+sum);}}8.第四章作业题1.classDengCha{intstart,d;DengCha(){}DengCha(intstart,intd){this.start=start;this.d=d;}voidsetStart(ints){start=s;}voidsetD(intd){this.d=d;}intgetSum(intn){intsum=0,i=1;while(i<=n){sum=sum+start;start=start+d;i++;}returnsum;}}publ
8、icclassZuoYe4_1{publicstaticvoidmain(Stringargs[]){DengChashulie=newDengCha(2,3);System.out.println(shulie.getSum(100));shulie.setStart(10);shuli