资源描述:
《java大学实用教程(第三版)课后习题答案》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、习题解答第一章作业题1.publicclassHello{publicstaticvoidmain(Stringargs[]){System.out.pintln("早上好,goodMorning”);importjava.applet.*;importjava.awt.*;publicclassBoyextendsApplet{publicvoidpaint(Graphicsg){g.setColor(Color.blue);g.drawString("你好,hello,,/12/30);第二章作业题publicclassZuoYe2_l{pu
2、blicstaticvoidmain(Stringargs[]){charc=,a,;System.out.println("字母"+c+"在unicode表中的顺序位置:"+(int)c);System.out.printlnC*字母表:while(c<='a,){System.out.print「H+c);c=(char)(c+l);2.importjava.util.*;publicclassZuoYe2_2{publicstaticvoidmain(Stringargs[]){Scannerreader二newScanner(System
3、.in);longchengji=l;intm=0;while(reader.hasNextlnt()){intx=reader.nextlnt();m=m+l;chengji=chengji*x;}System.out.println(m+H个数的乘积为H+chengji);第三章作业题1.importjava.util.*;publicclassZuoYe3_l{publicstaticvoidmain(Stringargs[]){Seannerreader=newSeanner(System.in);doubley=0,x=0;x=read
4、er.nextDouble();if(x<0)y=-l+2*x;elseif(x==O)y=-i;elseif(x>0)y=-l+3*x;System.out.println(y);}}2.publicclassZuoYe3_2{publicstaticvoidmain(Stringargs[]){intsurn=0‘m=3,n=7,a=l;while(a<=1000){if(a%m==O&&a%n==0)sum=sum+a;a++;}System.out.println(,,sum=,,+sum);}}3.publicclassZuoYe3_3
5、{publicstaticvoidmain(Stringargs[]){longsum=0,a=8Jtem=a,0)=1;for(i=l;i<二n;i++){sum=sum+item;item=item*10+a;System.out.println(sum);}}4.publicclassZuoYe3_4{publicstaticvoidmain(Stringargs[]){doublesum=0,a=l/b=l,fuhao=lJtem=a/b;inti=l;while(i<=1000){sum=sum+fuhao*item;i++;fuhao
6、=fuhao*(-l);b=b+2;item=a/b;}System.out.println(”sum二”+sum);}}5.publicclassZuoYe3_5{publicstaticvoidmain(Stringargs[]){doublesum=0,a=l;inti=l;while(i<=20){if(i>=10)sum=sum+a;i卄;a=a*i;}System.out.println("sum="+sum);}}第四章作业题classDengCha{intstart,d;DengCha(){}DengCha(intstart,in
7、td){this.start=start;this.d=d;}voidsetStartfints){start=s;}voidsetD(intd){this.d=d;}intgetSum(intn){intsum=0,i=l;while(i<=n){sum=sum+start;start=start+d;i++;}returnsum;}}publicclassZuoYe4_l{publicstaticvoidmain(Stringargs[]){DengChashulie二newDengCha(2,3);System.out.println(sh
8、ulie.getSum(100));shulie.setStart(lO);shulie.setD(5);System.out.prin