java期末考大题都在这.docxVIP

  • 6
  • 0
  • 约8.16千字
  • 约 20页
  • 2021-01-05 发布于山东
  • 举报
1.按要求编写一个 Java 应用程序: (1)定义一个接口 CanFly,描述会飞的方法 public void fly() 。 (2)分别定义类飞机和鸟,实现 CanFly 接口。 (3)定义一个测试类, 测试飞机和鸟,在 main 方法中创建飞机对象和鸟对象, 再定义一个 makeFly() 方法,其中让会飞的事物飞。 并在 main 方法中调用该方法,让飞机和鸟起飞。 interface CanFly { public void fly(); } class Plane implements CanFly{ public void fly() { Plain-fly); } } class Bird implements CanFly{ public void fly() { Bird-fly); } } class FlyTest { void makeFly(CanFly cf){ (); } public static void main(String[] args) { Plane p = new Plane(); Bird b = new Bird(); FlyTest test = new FlyTest(); (p); (b); } } 完数 P184-2 abstract class Number{ abstract void method(); } class Perfect extends Number{ void method(){ 2到 1000 的完数如下: ) ; int i, j, sum; for(i=2;i=1000;i++){ sum=0; for(j=1;j=i/2;j++){ if(i%j==0) sum=sum+j; } if(sum==i) ); } } } public class Test{ public static void main(String[] args){ Number n=new Perfect(); (); n=new Prime(); (); } } 4.按要求 写 Java 用程序。 写一个名 Test 的主 ,在主方法中定 一个大小 50 的一 整型数 ,数 名 x,数 中存放着 {1 , 3, 5, ?,99} , 出 个数 中的所有元素,每 出十个 一行 . public class Test { public static void main(String[] args) { int[] x=new int[50]; int i,j; for(i=0;i50;i++) { x[i]=2*i+1; if(i%10==0) { } ); } } } 写一个 JAVA程序 , 要求有如下输出 ( 使用数组 ) 第 0 行 01234 第 1 行 56789 2 行 10 11 12 13 14 3 行 15 16 17 18 19 4 行 20 21 22 23 24 class ArrayTest{ public static void main(String[] args){ int a[][]=new int[5][5]; int temp=0; for(int i=0;i;i++){ for(int j=0;j;j++){ a[i][j]=temp; temp++; } } for(int i=0;i;i++){ 第 +i+ 行-); for(int j=0;ja[0].length;j++){ ); } } } } .中国特色社会主义的体制中有这样的现象: 地方省政府要坚持党的领导和按照国务院的指示进行安全生产。 请编写一个 java 应用程序描述上述的体制现象。要求如下: (1) 该应用程序中有一个“党中央”接口: CentralPartyCommittee , 该接口中有个“坚持党的领导”方法: void partyLeader() 。 (2) 该应用程序中有一个“国务院”抽象类: StateCouncil , 该抽象类中有个“安全生产”的抽象方法: abstract void safetyInProduction() 。 (3) 该应用程序中有一个“省政府”类: Province , 该类继承 StateCouncil 抽象类并且实现 CentralPartyCommittee 接口; 在实现 partyLeader() 方法时输出“我们各省人民一定坚持党的领导! ”; 在重写 safetyInProduction() 方法时输出 “我们各省人民一定按照国务院的指示进行安全生产! ”。 (4) 该应用程序中有一个主类 E, 在主类 E 的 main 方法中创建 Province 类的对象,来测

文档评论(0)

1亿VIP精品文档

相关文档