您好,欢迎访问三七文档
当前位置:首页 > 高等教育 > 大学课件 > 《JAVA简明教程(第三版)》2-7单元答案
24n2311310000********************************************************************************************////*1:*/importjava.awt.*;importjava.util.*;importjava.applet.Applet;publicclassjiaoguextendsApplet{publicvoidpaint(Graphicsg){intx,n,i=10;for(x=3;x=10;x++){n=x;while(n!=1)if(n%2==0)n=n/2;elsen=n*3+1;g.drawString(x+!,25,25+i);i=i+15;}}}/**2:*/classjiaogu{publicstaticvoidmain(Stringargs[]){intx,n,i;for(x=3;x=1000;x++){n=x;while(n!=1)if(n%2==0)n=n/2;elsen=n*3+1;System.out.println(x+!);}}}/********************************************************************************************25applet2islargerthetwonumbersareequal!********************************************************************************************////**large.java*/importjava.applet.*;importjava.awt.*;publicclasslargeextendsApplet{Labellab1,lab2;TextFieldinput1,input2;intone,two;publicvoidinit(){lab1=newLabel();lab2=newLabel();input1=newTextField(6);input2=newTextField(6);add(lab1);add(input1);add(lab2);add(input2);}publicbooleanaction(Evente,Objecto){intmax;if(e.target==input1||e.target==input2){one=Integer.parseInt(input1.getText());two=Integer.parseInt(input2.getText());if(one==two)showStatus(!);else{max=(onetwo)?one:two;showStatus(max+!);}}returntrue;}}/********************************************************************************************262Math.random()272123636006736001/67123456123456723456783456789456789105678910116789101112********************************************************************************************////**dice.java***/publicclassdice{publicstaticvoidmain(String[]args){//Theratethatnumbersappeardoubleresult2;doubleresult7;doubleresult12;intn1,n2;intint1,int2;//Thetimesnumbersappearinttimes2=0;inttimes7=0;inttimes12=0;for(inti=0;i3600;i++){//generaterandomintn1=(int)(Math.random()*6+1);n2=(int)(Math.random()*6+1);if((n1+n2)==2)times2++;elseif((n1+n2)==7)times7++;elseif((n1+n2)==12)times12++;}result2=times2/3600.0;result7=times7/3600.0;result12=times12/3600.0;System.out.println(2:+times2+:+result2);System.out.println(7:+times7+:+result7);System.out.println(12:+times12+:+result12);}}/********************************************************************************************3153243932439********************************************************************************************////**deduct.java*/importjava.applet.*;importjava.awt.*;publicclassdeductextendsApplet{Stringstr;TextFieldinput;LabelLinput;publicvoidinit(){Linput=newLabel();input=newTextField(10);add(Linput);add(input);}publicbooleanaction(Evente,Objecto){if(e.target==input){str=input.getText();showStatus(+str);}repaint();returntrue;}publicvoidpaint(Graphicsg){for(inti=0;istr.length();i++)g.drawString(str.charAt(i)+,50+i*10,50);}}/********************************************************************************************320100001112483927101001000********************************************************************************************////**num.java*/importjava.applet.*;importjava.awt.*;publicclassnumextendsApplet{publicvoidpaint(Graphicsg){g.drawString(,20,15);g.drawString(,80,15);g.drawString(,140,15);for(inti=0;i=10;i++){g.drawString(+i,20,30+i*20);g.drawString(+i*i,80,30+i*20);g.drawString(+i*i*i,140,30+i*20);}}}//publicclassnum2{publicstaticvoidmain(String[]args){inti=0;intresult;System.out.println(++);for(;i=10;i++){result=i;System.out.print(i+);result=result*i;System.out.print(+result);result=result*i;System.out.print(+result);System.out.println();}}}/********************************************************************************************33**************************************************************************************************************************////**graph1.java*/publicclassgraph1{//drawnstarsstaticvoidstar(intn){for(inti=1;i=n;i++){System.out.print(*);}}//drawnspacesstaticvoidspace(intn){for(inti=1;i=n;i++){System.out.print();}}publicstaticvoidmain(String[]args){//thelengthofspaceinti=20;//thelengthofstarintj=1;for(j=1;j=5;j++){star(j);space(i);star(j);i-=2;System.out.println();}}}/********************************************************************************************345************************************************************************************************************////**graph2.java*/publicclassgraph2extendsApplet{intnum;TextFieldinput;LabelLinput;publicvoidinit(){Linput=newLabel(Enteraninteger:);input=newTextField(10);add(Linput);add(input);}publicbooleanaction(Evente,Objecto){if(e.target==input)num=Integer.parseInt(input.getText());repaint();returntrue;}publicvoidpaint(Graphicsg){inti,j;for(i=0;inum;i++)if(i==0||i==num-1)for(j=0;jnum;j++)g.drawString(*,30+10*j,50+10*i);else{g.drawString(*,30,50+10*i);g.drawString(*,30+10*(num-1),50+10*i);}}}/**graph2_1.java*/publicclassgraph2_1{privateintnumber;publicNO_2_4(intnumber){this.number=number;draw(number);}//drawsquarepublicvoiddraw(intn){if(n==1)System.out.println(*);else{stars(n);System.out.println();for(inti=0;in;i++){stars(1);space(n-2);stars(1);System.out
本文标题:《JAVA简明教程(第三版)》2-7单元答案
链接地址:https://www.777doc.com/doc-8695614 .html