JAVA实验报告(一二三次实验代码完整版--矿大).doc

上传人:飞****2 文档编号:52778801 上传时间:2022-10-23 格式:DOC 页数:36 大小:320.50KB
返回 下载 相关 举报
JAVA实验报告(一二三次实验代码完整版--矿大).doc_第1页
第1页 / 共36页
JAVA实验报告(一二三次实验代码完整版--矿大).doc_第2页
第2页 / 共36页
点击查看更多>>
资源描述

《JAVA实验报告(一二三次实验代码完整版--矿大).doc》由会员分享,可在线阅读,更多相关《JAVA实验报告(一二三次实验代码完整版--矿大).doc(36页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。

1、第一题:public class chengfabiaopublic static void main(String args)System.out.println(*+ +1+ +2+ +3+ +4+ +5+ +6+ +7+ +8+ +9);int i;int j;for(i=1;i=9;i+)System.out.print(i+ );for(j=1;j0) /月份数大于0进入循环switch(mon)case 1:System.out.println(January);break;case 2:System.out.println(February);break;case 3:Syste

2、m.out.println(March);break;case 4:System.out.println(April);break;case 5:System.out.println(May);break;case 6:System.out.println(June);break;case 7:System.out.println(July);break;case 8:System.out.println(August);break;case 9:System.out.println(September);break;case 10:System.out.println(October);br

3、eak;case 11:System.out.println(November);break;case 12:System.out.println(December);break;System.out.println(Please input your nubmers:);in = new Scanner(System.in); mon = in.nextInt();第三题:import java.util.Scanner;public class sanjiaopublic static void main(String args)int i,j,k,number;System.out.pr

4、intln(Please input your nubmers:);Scanner in = new Scanner(System.in);number = in.nextInt();while(number0)for(i=1;i=1;j-)System.out.print( );for(k=1;k=i;k+)System.out.print(*+ );System.out.println();System.out.println(Please input your nubmers:);in = new Scanner(System.in);number = in.nextInt();第四题:

5、public class sxhpublic static void main(String args)int shuixian,n=1;for(int i=1;i=9;i+)for(int j=0;j=9;j+)for(int k=0;k=9;k+)if(i*100+j*10+k)=(i*i*i+j*j*j+k*k*k) shuixian=i*100+j*10+k;System.out.print(shuixian+ );n+;if(n=5)System.out.println();n=1;第五题:import java.util.Scanner;public class paixupubl

6、ic static void main(String args)int i;int j;int k;int m;int shu;shu=new int10;System.out.println(Please input ten nubmers:);Scanner in = new Scanner(System.in);for(i=0;i=0;j-)for(k=0;kshuk+1)int temp;temp=shuk;shuk=shuk+1;shuk+1=temp;for(m=0;m10;m+)System.out.print(shum+ );第七题:import java.util.Rando

7、m;import java.io.*;public class shuz public static void main(String args) inta=new int66;int i,j;double x=0;Random rand= new Random();for(i=0;i6;i+)for(j=0;j6;j+)aij=10+rand.nextInt(11);System.out.println(初始化矩阵: );for(i=0;i6;i+)for(j=0;j6;j+)System.out.print(aij+ );System.out.println();for(i=0;i6;i+

8、)for(j=0;jnum2)temp1=solution1(num1,num2);temp2=solution2(num1,num2);elsetemp1=solution1(num2,num1);temp2=solution2(num2,num1);System.out.println(循环法得到+num1+和+num2+的最大公约数为:+temp1);System.out.println(递归法得到+num1+和+num2+的最大公约数为:+temp2);private static int solution1(int x,int y)int r;while(y!=0)r=x%y;x=y

9、;y=r;return x;private static int solution2(int m,int n)if(n=0)return m;elsereturn solution2(n,m%n);第二题:package two;public class House private String hname;private int hlength;private int hwidth;private int hheight;public House(String hname,int hlength,int hwidth,int hheight)this.hname=hname;this.hle

10、ngth=hlength;this.hwidth=hwidth;this.hheight=hheight;public void Print()System.out.println(房子名称:+gethname();System.out.println(房子长度:+this.hlength);System.out.println(房子宽度:+gethwidth();System.out.println(房子高度:+this.hheight);public void sethname(String hname)this.hname=hname;public String gethname()re

11、turn hname;public void sethwidth(int hwidth)this.hwidth=hwidth;public int gethwidth()return hwidth;package two;public class leiprogram public static void main(String args)Tool tool1=new Tool(剪刀,2000);tool1.Print();tool1.Settname(锤子);tool1.Settyear(2012);tool1.Print();House house1=new House(普通房子,20,1

12、0,3);house1.Print();house1.sethname(教室);house1.sethwidth(15);house1.Print();package two;public class Tool private String tname;private int tyear;public Tool(String tname,int tyear)this.tname=tname;this.tyear=tyear;public void Print()System.out.println(工具名称:+gettname();System.out.println(工具制造年份:+gett

13、year();public void Settname(String tname)this.tname=tname;public String gettname()return tname;public void Settyear(int tyear)this.tyear=tyear;public int gettyear()return tyear;第三题:package three;public class Circle private int x,y,r;Circle()x=y=r=0;Circle(int x,int y,int r)this.x=x;this.y=y;this.r=r

14、;public void setxy(int x,int y)this.x=x;this.y=y;public void setr(int r)this.r=r;public double zhou()return 2*3.14*r;public double mian()return 3.14*r*r;public void Print()System.out.println(圆心位置:(+x+,+y+);System.out.println(元的半径:+r);package three;public class yuancase public static void main(String

15、 args)Circle c=new Circle(1,1,3);c.Print();System.out.println(周长为:+c.zhou();System.out.println(面积为:+c.mian();第四题:package four;public class Classroom extends House private String hschoolname;public Classroom(String hname,int hlength,int hwidth,int hheight,String hschoolname)super(hname,hlength,hwidth

16、,hheight);this.hschoolname=hschoolname;public void Print()super.Print();System.out.println(学校名称:+this.hschoolname);package four;public class House private String hname;private int hlength;private int hwidth;private int hheight;public House(String hname,int hlength,int hwidth,int hheight)this.hname=h

17、name;this.hlength=hlength;this.hwidth=hwidth;this.hheight=hheight;public void Print()System.out.println(房子名称:+gethname();System.out.println(房子长度:+this.hlength);System.out.println(房子宽度:+gethwidth();System.out.println(房子高度:+this.hheight);public void sethname(String hname)this.hname=hname;public String

18、 gethname()return hname;public void sethwidth(int hwidth)this.hwidth=hwidth;public int gethwidth()return hwidth;package four;public class jicheng public static void main(String args)Classroom class1=new Classroom(普通房子,20,10,3,中国矿业大学);class1.Print();Pen pen1=new Pen(钢笔,2012,20);pen1.Print();package f

19、our;public class Pen extends Tool private int tweight;public Pen(String tname,int tyear,int tweight)super(tname,tyear);this.tweight=tweight;public void Print()super.Print();System.out.println(重量:+this.tweight);package four;public class Tool private String tname;private int tyear;public Tool(String t

20、name,int tyear)this.tname=tname;this.tyear=tyear;public void Print()System.out.println(工具名称:+gettname();System.out.println(工具制造年份:+gettyear();public void Settname(String tname)this.tname=tname;public String gettname()return tname;public void Settyear(int tyear)this.tyear=tyear;public int gettyear()r

21、eturn tyear;第五题:package five;public class Circle protected int centre_x,centre_y;protected int radius;public Circle(int x,int y,int r)centre_x=x;centre_y=y;radius=r;public double zhou()return 2*3.14*radius;public double mian()return 3.14*radius*radius;package five;public class Yuanzhu extends Circle

22、private int height;public Yuanzhu(int x,int y,int r,int height)super(x,y,r);this.height=height;public double mian()return 2*super.mian()+height*super.zhou();public double ti()return height*super.mian();package five;public class zhulei public static void main(String args)Circle circle1=new Circle(3,4

23、,5);Yuanzhu yuanzhu1=new Yuanzhu(3,4,5,6);System.out.println(circle1 的周长为:+circle1.zhou();System.out.println(circle1的面积为:+circle1.mian();System.out.println(yuanzhu1的面积为:+yuanzhu1.mian();System.out.println(yuanzhu1的体积为:+yuanzhu1.ti();第六题:package six;public class casemain public static void main(Strin

24、g args)Classes class1;class1=new Classes(cs09-1);class1.Studentlist();package six;public class Classes private String classname;private Student students;public Classes(String classname)this.classname=classname;public void Studentlist()System.out.println(学生名单:);students=new Student6;students0=new Stu

25、dent(3342,yaowei,cs09-1);students1=new Student(3343,yuyong,cs09-1);students2=new Student(3341,wuqiang,cs09-1);students3=new Student(3337,yuxiang,cs09-1);students4=new Student(3339,wanghao,cs09-1);students5=new Student(3336,sunhao,cs09-1);for(int i=0;i6;i+)System.out.println(学生+(i+1)+的信息+:);System.ou

26、t.println(学号+studentsi.getid();System.out.println(名字+studentsi.getname();System.out.println(班级+studentsi.get();package six;public class Person protected int id;protected String name;protected String sex;public Person(int id,String name)this.id=id;this.name=name;public void setid(int id)this.id=id;pu

27、blic void setname(String name)this.name=name;public int getid()return id;public String getname()return name;package six;public class Student extends Personprivate String sclass;public Student(int id,String name,String sclass)super(id,name);this.sclass=sclass;public void set(String sclass)this.sclass

28、=sclass;public String get()return sclass;package six;public class Teacher extends Personprivate String major;public Teacher(int id,String name,String major)super(id,name);this.major=major;public void set(String major)this.major=major;public String get()return major;public void Teacher(int i, String

29、string, String string2) / TODO Auto-generated method stub第七题:人员包:package person;public class Student extends six.Personprivate String sclass;public Student(int id,String name,String sclass)super(id,name);this.sclass=sclass;public void set(String sclass)this.sclass=sclass;public String get()return sc

30、lass;package person;public class Teacher extends six.Personprivate String major;public Teacher(int id,String name,String major)super(id,name);this.major=major;public void set(String major)this.major=major;public String get()return major;管理包:package manage;import six.Student;public class Class privat

31、e String classname;private Student students;public Class(String classname)this.classname=classname;public void Studentlist()System.out.println(学生名单:);students=new Student6;students0=new Student(3342,yaowei,cs09-1);students1=new Student(3343,yuyong,cs09-1);students2=new Student(3341,wuqiang,cs09-1);s

32、tudents3=new Student(3337,yuxiang,cs09-1);students4=new Student(3339,wanghao,cs09-1);students5=new Student(3336,sunhao,cs09-1);for(int i=0;i6;i+)System.out.println(学生+(i+1)+的信息+:);System.out.println(学号+studentsi.getid();System.out.println(名字+studentsi.getname();System.out.println(班级+studentsi.get();

33、package manage;import java.util.Scanner;public class Tsourse protected String schoolname;protected int idhao;protected String teaname,teamajor;public Tsourse(String schoolname,int idhao,String teaname,String teamajor)this.schoolname=schoolname;this.idhao=idhao;this.teaname=teaname;this.teamajor=team

34、ajor;public String getschoolname()return schoolname;public int getidhao()return idhao;public String getteaname()return teaname;public String getteamajor()return teamajor;public void print()System.out.println(学校+getschoolname();System.out.println(id+getidhao();System.out.println(名字+getteaname();Syste

35、m.out.println(授课+getteamajor();用户包:package use;import manage.Tsourse;public class Use public static void main(String args)manage.Tsourse tsourse;tsourse=new manage.Tsourse3;tsourse0=new manage.Tsourse(cumt,0001,mrli,cs);tsourse1=new manage.Tsourse(cumt,0002,mrwang,cs);tsourse2=new manage.Tsourse(cumt,0003,mrzhang,cs);for(int i=0;i3;i+)System.out.println(教师+(i+1)+的信息+:);tsoursei.print();第八题:package eight;public class cumt implements Jiekouprivate String schoolname;public cumt(String name)schoolname=n

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 教育专区 > 教案示例

本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

工信部备案号:黑ICP备15003705号© 2020-2023 www.taowenge.com 淘文阁