資源描述:
《Java張永常版實(shí)驗(yàn)報(bào)告》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在教育資源-天天文庫。
1、第三章:第七題:importjava.io.*;publicclassXiTi3_7{publicstaticvoidmain(String[]args){intm=0;for(inti=0;i<=100;i++)if(i%2==0)m=m+i;System.out.println("所有偶數(shù)的和:"+m);intn=0;for(intj=0;j<=100;j++)if(j%2!=0)n=n+j;System.out.println("所有奇數(shù)的和:"+n);}}第三章:第九題:importjava.io.*;publicclassXiTi3_9{publicstaticvoidmain(
2、String[]args)throwsIOException{doubles=1;doublex,m,n=1;inti=1;Stringstr;BufferedReaderbuf=newBufferedReader(newInputStreamReader(System.in));str=buf.readLine();x=Integer.parseInt(str);do{s=s*i;m=1/s;if(m>=1e-4)n=n+m;i++;}while(i<=x);System.out.println(n);}}第三章:importjava.io.*;publicclassXiTi4_7{pu
3、blicstaticvoidmain(String[]args){intscore[][];score=newint[9][9];inti,j;for(i=0;i<9;i++){for(j=0;j<=10-i;j++)System.out.print("");for(j=0;j<=i;j++){if(j==0
4、
5、i==0)score[i][0]=1;elseif(j==i)score[j][j]=1;elsescore[i][j]=score[i-1][j]+score[i-1][j-1];System.out.print(""+score[i][j]+"");}System.out.pr
6、intln();}}}第四章:importjava.io.*;classComplex{floata,b;publicComplex(){this.a=0;this.b=0;}}classMyComplexextendsComplex{publicvoidJiaFa(floatx1,floatx2,floaty1,floaty2){a=x1+x2;b=y1+y2;System.out.println("得到和的結(jié)果為: "+"("+a+","+b+")");}publicvoidChengFa(floatx1,floatx2,floaty1,floaty2){a=x1*x2-y1*y2;
7、b=x1*y2+x2*y1;System.out.println("得到積的結(jié)果為: "+"("+a+","+b+")");}publicvoidJianFa(floatx1,floatx2,floaty1,floaty2){a=x1-x2;b=y1-y2;System.out.println("得到差的結(jié)果為: "+"("+a+","+b+")");}}publicclassShiYan4_2_1{publicstaticvoidmain(String[]args){MyComplexfushu=newMyComplex();fushu.JiaFa(1f,2f,3f,4f);fush
8、u.ChengFa(1f,2f,3f,4f);fushu.JianFa(1f,2f,3f,4f);}