資源描述:
《java 大學(xué)實(shí)用教程(第2版)》由會(huì)員上傳分享,免費(fèi)在線(xiàn)閱讀,更多相關(guān)內(nèi)容在行業(yè)資料-天天文庫(kù)。
1、習(xí)題解答第一章作業(yè)題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、章作業(yè)題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{publicstat
3、icvoidmain(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+"個(gè)數(shù)的乘積為"+chengji);}}第三章作業(yè)題1.importjava.util.*;publicclassZuoYe3_1{publicstatic
4、voidmain(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=0,m=3,n=7,a=1;while
5、(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(sum);}}4.publicclassZuoYe3
6、_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{publicstaticvoidmain(Stringargs[]){doublesum=0,
7、a=1;inti=1;while(i<=20){if(i>=10)sum=sum+a;i++;a=a*i;}System.out.println("sum="+sum);}}8.第四章作業(yè)題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){ints
8、um=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