资源描述:
《java大学实用教程(第2版).doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
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)
2、;}}第二章作业题1.publicclassZuoYe2_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{
3、publicstaticvoidmain(Stringargs[]){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
4、_1{publicstaticvoidmain(Stringargs[]){Scannerreader=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
5、=0,m=3,n=7,a=1;while(a<=1000){if(a%m==0&&a%n==0)sum=sum+a;a++;}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(s
6、um);}}4.publicclassZuoYe3_4{publicstaticvoidmain(Stringargs[]){doublesum=0,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{publicstaticvoidm
7、ain(Stringargs[]){doublesum=0,a=1;inti=1;while(i<=20){if(i>=10)sum=sum+a;i++;a=a*i;}System.out.println("sum="+sum);}}8.第四章作业题1.classDengCha{intstart,d;DengCha(){}DengCha(intstart,intd){this.start=start;this.d=d;}voidsetStart(ints){start=s;}voidsetD(i
8、ntd){this.d=d;}intgetSum(intn){intsum=0,i=1;while(i<=n){sum=sum+start;start=start+d;i++;}returnsum;}}publicclassZuoYe4_1{publicstaticvoidmain(Stringargs[]){DengChashulie=newDengCha(2,3);System.out.println(shulie.getSum(100));shulie.setStart(10);shuli