欢迎来到天天文库
浏览记录
ID:38485058
大小:54.50 KB
页数:13页
时间:2019-06-13
《java练习代码》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、BooksTestDrive.javaclassBooks{Stringtitle;Stringauthor;}publicclassBooksTestDrive{publicstaticvoidmain(String[]args){Books[]mybooks=newBooks[3];mybooks[0]=newBooks();//创建books的对象mybooks[1]=newBooks();mybooks[2]=newBooks();intx=0;mybooks[0].title="english";myboo
2、ks[1].title="math";mybooks[2].title="chinese";mybooks[0].author="Mark";mybooks[1].author="Tina";mybooks[2].author="Peter";while(x<3){System.out.print(mybooks[x].title+""+"by"+""+mybooks[x].author);System.out.println("");x=x+1;}}}Dog.javapublicclassDog{Stringnam
3、e;//变量有两种:基本数据类型和引用数据类型;变量声明时必须要有类型和名称publicstaticvoidmain(String[]args){//创建dog对象Dogdog1=newDog();dog1.bark();dog1.name="mark";//创建dog数组Dog[]mydogs=newDog[3];//数组也属于对象,数组的引用既是对象的引用mydogs[0]=newDog();mydogs[1]=newDog();mydogs[2]=dog1;//通过数组引用存取dogmydogs[0].name
4、="tina";mydogs[1].name="peter";//dog2的名字?System.out.println("whatisthedog2'sname?");System.out.println(mydogs[2].name);//对dog逐个执行bark()方法intx=0;while(x5、.javapublicclassDogTestDrive{publicstaticvoidmain(String[]args){Dogd=newDog();//建立一个dog对象d.size=40;d.bark();}}classDog{intsize;Stringbreed;Stringname;voidbark(){System.out.println("youareafooldog!");}}DooBee.javapublicclassDooBee{publicstaticvoidmain(String[]ar6、gs){intx=1;while(x<3){System.out.print("Doo");System.out.print("Bee");x++;}if(x==3){System.out.print("Do");}}}DrumKitTestDrive.javaclassDrumKit{booleantopHat=true;booleansnare=true;voidplayTopHat(){System.out.println("dingdingda-ding");}voidplaySnare(){System.o7、ut.println("bangbangba-bang");}}classDrumKitTestDrive{publicstaticvoidmain(String[]args){DrumKitd=newDrumKit();d.snare=false;d.playSnare();d.playTopHat();if(d.snare==true){d.playSnare();}}}EchoTestDrive.javapublicclassEchoTestDrive{publicstaticvoidmain(String[]8、args){Echoe1=newEcho();Echoe2=newEcho();intx=0;while(x<4){e1.hello();e1.count=e1.count+1;if(x==3){e2.count=e2.count+1;}if(x>0){e2.count=e2.count+e1.count;}x=x+1;}System.out.
5、.javapublicclassDogTestDrive{publicstaticvoidmain(String[]args){Dogd=newDog();//建立一个dog对象d.size=40;d.bark();}}classDog{intsize;Stringbreed;Stringname;voidbark(){System.out.println("youareafooldog!");}}DooBee.javapublicclassDooBee{publicstaticvoidmain(String[]ar
6、gs){intx=1;while(x<3){System.out.print("Doo");System.out.print("Bee");x++;}if(x==3){System.out.print("Do");}}}DrumKitTestDrive.javaclassDrumKit{booleantopHat=true;booleansnare=true;voidplayTopHat(){System.out.println("dingdingda-ding");}voidplaySnare(){System.o
7、ut.println("bangbangba-bang");}}classDrumKitTestDrive{publicstaticvoidmain(String[]args){DrumKitd=newDrumKit();d.snare=false;d.playSnare();d.playTopHat();if(d.snare==true){d.playSnare();}}}EchoTestDrive.javapublicclassEchoTestDrive{publicstaticvoidmain(String[]
8、args){Echoe1=newEcho();Echoe2=newEcho();intx=0;while(x<4){e1.hello();e1.count=e1.count+1;if(x==3){e2.count=e2.count+1;}if(x>0){e2.count=e2.count+e1.count;}x=x+1;}System.out.
此文档下载收益归作者所有