java编程期末复习(共16页).docx
《java编程期末复习(共16页).docx》由会员分享,可在线阅读,更多相关《java编程期末复习(共16页).docx(16页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、精选优质文档-倾情为你奉上编程题:1编写一个输出Hello World!的程序,用两种方式实现(Application、Applet)。application程序public class apublic static void main(String args)System.out.println(Hello World!);2、applet程序public class b extends java.applet.Appletpublic paint(java.awt.Graphics g)g.outstring(Hello World!,10,10);2.求10个数中的最小值并输出。impo
2、rt java.util.Scanner;public class Test public static void main(String args)int num=new int10;int min;Scanner scan=new Scanner(System.in);System.out.print(请输入10个数字:);for(int i=0; i10; i+)numi=scan.nextInt();min=num0;for(int i=1; inumi) min=numi;System.out.println(最小值是+min);3.建立一个学生类,其中成员变量为学号,姓名,及三门课
3、成绩。另外建立一个包含主方法的类,定义2个学生类的对象,求出这2个学生三门课总分的最高分,并将最高分这个学生的信息输出。class student String name,no; float eng,math,chi; public student(String name1,String no1,float eng1,float math1,float chi1)name=name1;no=no1;eng=eng1;math=math1;chi=chi1;float sum() return(eng+math+chi);void print() System.out.println(name:
4、+name+t no:+no+t total:+sum();public class maxpublic static void main(String args)student s1=new student(lily,001,80,90,50);student s2=new student(lucy,002,70,70,70);if (s1.sum()s2.sum() s1.print();else s2.print();4请编写一个实现如下功能的Application:比较从键盘输入的两个整数是否相等,并根据比较结果显示“相等”或“不相等”。import java.util.Scanner
5、;public class COMPare public static void main(String args )Scanner tr=new Scanner(System.in);int b=tr.nextInt();int a=tr.nextInt();if(a=b) System.out.println(相等);else System.out.println(不相等);5.编写一个Application,利用数组求出”HELLO”,”JAVA”PROGRAM”三个字符串的平均长度。class Average public static void main(String args) S
6、tring array = new String3;array0 = HELLO;array1 = JAVA;array2 = PROGRAM;int total = array0.length();total += array1.length();total += array2.length();System.out.println(平均字符串长度为: + total/3);6、习题(6_13): import java.util.*;class StudentString num;String name;String sex;boolean cleader;float math;float
7、 chn;float eng;public Student(String newNum,String newName,String newSex,boolean newCleader,float newMath,float newChn,float newEng)num=newNum;name=newName;sex=newSex;cleader=newCleader;math=newMath;chn=newChn;eng=newEng;public float sum()return math+chn+eng;public float ave()return sum()/3;public v
8、oid output()System.out.println(num+t+name+t+sex+t+cleader+tt+math+t+chn+t+eng+t+sum()+t+ave();public class book6_13_2public static void main(String args)String newNum,newName,newSex;boolean newCleader;float newMath,newChn,newEng;Student s=new Student3;for(int i=1;i=s.length;i+)System.out.println(请输入
9、第+i+个学生的信息);Scanner reader=new Scanner(System.in);System.out.print(请输入该学生学号:);newNum=reader.nextLine();System.out.print(请输入该学生姓名:);newName=reader.nextLine();System.out.print(请输入该学生性别:);newSex=reader.nextLine();System.out.print(请输入该学生是否为班干部:);newCleader=reader.nextBoolean();System.out.print(请输入该学生数学成
10、绩:);newMath=reader.nextFloat();System.out.print(请输入该学生语文成绩:);newChn=reader.nextFloat();System.out.print(请输入该学生英语成绩:);newEng=reader.nextFloat();si-1=new Student(newNum,newName,newSex,newCleader,newMath,newChn,newEng);System.out.println(学号t姓名t性别t班干部否t数学t语文t英语t总分t平均分);for(int i=1;i=s.length;i+)si-1.out
11、put();7、/第5章第11题import java.io.*;public class Exercises5_11 public static void main(String args) throws IOException String str; BufferedReader buf; buf=new BufferedReader(new InputStreamReader(System.in); System.out.print(请输入字符串,输入exit退出:); do str=buf.readLine(); System.out.println(str); while(!str.
12、equals(exit); 8、定义一个Person类,该类具有姓名、身高、体重、年龄属性,能够对上述相关信息进行输出display()。由Person类派生出China类,增加爱好属性。.class Person private String name; private int age; private float hight; private float weight; public Person(String n,int a,float h,float w) name=n; age=a; hight=h; weight=w; public void show() System.out.p
13、rintln(Person name =+name +,age= + age + , hight= + hight + , weight= + weight + ); class China extends Person private String hobby; public China(String n,int a,float h,float w,String hob)super(n,a,h,w); hobby=hob; public void display() System.out.println( China hobby= + hobby + ); public class E8_1
14、 public static void main(String args) China cc =new China(wenwen,23,168,104,sing); cc.show(); cc.display(); 9、创建一个图形类,包括计算图形面积的方法。创建两个子类长方形、圆形,分别继承图形类,重写子类中的计算图形面积的方法。写一个测试类,分别创建一个长方形和圆形类的对象,并且分别计算这两个图形的面积./filename:app8_2.java 抽象类的说明abstract class Shape protected String name; public Shape(String xm
15、) name=xm; System.out.print(名称:+name); abstract public double getArea();class Circle extends Shape private final double PI=3.14; private double radius; public Circle(String shapeName,double r) super(shapeName); radius=r; public double getArea() return PI*radius*radius; class Rectangle extends Shape
16、private double width; private double height; public Rectangle(String shapeName,double width,double height) super(shapeName); this.width=width; this.height=height; public double getArea() return width*height; public class E8_2 public static void main(String args) Shape rect =new Rectangle(长方形,6.5,10.
17、3); System.out.println(;面积=+rect.getArea(); Shape circle=new Circle(圆,10.2); System.out.println(;面积=+circle.getArea(); 10、编写一个“Student”类,该类拥有属性:校名、学号、性别、出生日期。方法包含构造方法和输出方法。再编写“Student”类的子类:Undergraduate(大学生)。Undergraduate类除拥有父类属性和方法外,还有其自己的属性和方法:附加属性包括系(department)、专业(major);方法包含构造方法和输出方法。class Stud
18、ent String name; int sNum; String sex; String birth; String sname; int Score; public Student(String name1,int sNum1, String sex1,String birth1, String sname1,int Score1) name=name1; sNum=sNum1; sex=sex1; birth=birth1; sname=sname1; Score=Score1; void show() System.out.println(所在学校:+name); System.out
19、.println(学号:+sNum); System.out.println(性别:+sex); System.out.println(生日:+birth); System.out.println(姓名:+sname); System.out.println(成绩:+Score); class Undergraduate extends Student String department; String major; public Undergraduate(String name1,int sNum1, String sex1,String birth1, String sname1,int
20、 Score1,String department1,String major1) super(name1,sNum1,sex1, birth1, sname1, Score1); department=department1; major=major1; void show1() super.show(); System.out.println(系部:+department); System.out.println(专业:+major); public class aa public static void main(String arg) Undergraduate B=new Under
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- java 编程 期末 复习 16
限制150内