欢迎来到天天文库
浏览记录
ID:35442674
大小:77.94 KB
页数:5页
时间:2019-03-24
《西电java上机作业2实验报告》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、JAVA上机作业2一•题目描述:1•面向对象程序设计实验定义普通人、老师、班主任、学生、学校,提供适当的属性、方法用于描述其内部数据和行为方式,并提供主类使之运行。2.用Java实现一个复杂算法吸血鬼数字是指位数为偶数的数字,可以由一对数字相乘得到,这对数字各包含乘积的一半位数的数字,数字选取后可任意排序。例如,下列数字都是“吸血鬼”数字:1260=21X601827=21X872187=27X81写出一个程序,找出4位数的所有吸血鬼数字。二.源代码:1•面向对象程序设计实验classPeopleForSchool{Strin
2、gteacher;Stringstudent;publicPeopleForSchool(Stringteacher,Stringstudent){this.teacher二teacher;this.student=student;}publicStringgctDctails(){return"Atschool:〃+teacher+〃isateacherand〃+student+〃isastudent.〃;classHeadteacherextendsPeopleForSchool{privateStringmanage_s
3、tudent;publicHeadteacher(Stringteacher,Stringstudent,Stringmemagc_studcnt){super(teacher,student);this.manage_student=manage_student;}""publicStringgctDctails(){returnsuper.getDetails()+,zespecially,,,+teacher+,zalsoisa/z+manage_student+/z!〃;}"}publicclassMainclass{
4、publicstaticvoidmain(StringE]args){Headteacherm二newHeadteacher(/zTomz/,"headteacher");System,out.print1n(m.getDetai1s());2.吸血鬼数字源代码://importjava,utiLArrays;publieclassTheVampaireNumber{publicstaticvoidmain(String[]args)intnuml,num2,num;String[]strl,str2;inti,j;for(n
5、uml=10;numKIOO;numl++){i二Math./77<^%(1OOO/numl,numl+1);j=Math,min(10000/numl,100);for(num2=i;num26、tr2);if(Arrays,equalsgtri,str2)){Systcm.out.printin(numl+〃*〃+nuni2+〃二〃+num);}}}}三•运行结果:1•面向对象程序设计①Vimpaire.javaQ)Va.java©TheVampaireNumber.java^aindassjavaDTheMainClass.java23I20121publicHeadteacher(Stringteacher^Stringstudent^StringManagerstudent){22super(teacherst7、uden8、t);23this・manage_student=manage_student;24}25■26・publicStringgetDetails(){27returnsuper.getDetails()4Mespecidlly,"♦teacher^-alsoisa•♦manage_student*M28}29}30publicclassTheMainClass{31-publicstaticvoidmain(Stringf]args){32Headteacherm«newHeadteather(To9、headteavher*);33System.out.printIn(m.getDetai1s());3435}36}37v:».h::陀〔m山SConsoleHTheMainClass(JavaApplication]C:ProgramFilesV
6、tr2);if(Arrays,equalsgtri,str2)){Systcm.out.printin(numl+〃*〃+nuni2+〃二〃+num);}}}}三•运行结果:1•面向对象程序设计①Vimpaire.javaQ)Va.java©TheVampaireNumber.java^aindassjavaDTheMainClass.java23I20121publicHeadteacher(Stringteacher^Stringstudent^StringManagerstudent){22super(teacherst
7、uden
8、t);23this・manage_student=manage_student;24}25■26・publicStringgetDetails(){27returnsuper.getDetails()4Mespecidlly,"♦teacher^-alsoisa•♦manage_student*M28}29}30publicclassTheMainClass{31-publicstaticvoidmain(Stringf]args){32Headteacherm«newHeadteather(To9、headteavher*);33System.out.printIn(m.getDetai1s());3435}36}37v:».h::陀〔m山SConsoleHTheMainClass(JavaApplication]C:ProgramFilesV
9、headteavher*);33System.out.printIn(m.getDetai1s());3435}36}37v:».h::陀〔m山SConsoleHTheMainClass(JavaApplication]C:ProgramFilesV
此文档下载收益归作者所有