四川大学java上机题库

上传人:第*** 文档编号:34040642 上传时间:2018-02-20 格式:DOC 页数:11 大小:99KB
返回 下载 相关 举报
四川大学java上机题库_第1页
第1页 / 共11页
四川大学java上机题库_第2页
第2页 / 共11页
四川大学java上机题库_第3页
第3页 / 共11页
四川大学java上机题库_第4页
第4页 / 共11页
四川大学java上机题库_第5页
第5页 / 共11页
点击查看更多>>
资源描述

《四川大学java上机题库》由会员分享,可在线阅读,更多相关《四川大学java上机题库(11页珍藏版)》请在金锄头文库上搜索。

1、 输入三角形的三边 a, b, c,判断能否构成三角形。若能,计算周长。输出结果如下:input:请输入三个整数2 2 3 output:能构成三角形,周长为 7input:请输入三个整数1 2 3output:不能构成三角形import java.util.Scanner; public class main public static void main(String args) System.out.print(input:n 请输入三个整数 n); Scanner cin=new Scanner(System.in); int a=cin.nextInt(); int b=cin.ne

2、xtInt(); int c=cin.nextInt(); System.out.print(output:n); if(a+b3000) System.out.println(error); System.exit(0); if (year%4=0)&(year%100!=0)|(year%400=0) System.out.println(year+ is bissextile); else System.out.println(year+ is not bissextile ); 两个乒乓球队进行比赛,各出三人。甲队为 a,b,c 三人,乙队为 x,y,z 三人。已抽签决定比赛名单。有人

3、向队员打听比赛的名单。a 说他不和 x 比,c 说他不和 x,z 比,请编程序找出三队赛手的名单。输出结果格式如下图所示import java.util.*; public class main static char m=a,b,c; static char n=x,y,z; public static void main(String args) System.out.println(output:n 比赛名单如下所示); for(int i=0;i6 )个数字,然后从 S 中再选择 6 个数字作为最终选定的号码。你的任务是,给你 k 和集合 S,输出从 S 中选择投注号码的所有组合。im

4、port java.util.*; public class main public static void main(String args) Scanner s=new Scanner(System.in); boolean is=true; System.out.print(请输入一个正整数 : ); long a=s.nextLong(); String ss=Long.toString(a); char ch=ss.toCharArray(); int j=ch.length; for(int i=0;imax) max=ai; idx1=i; if(ai= 0 else if (c

5、hi = a & chi = A & chi 0.0) printString =Double.toString(p.real) + + + Double.toString(plex) + i; else printString =Double.toString(p.real) + Double.toString(plex) + i; System.out.print(printString + rn); public static void main(String args) new main(); 、定义一个名为 Vehicles(交通工具)的基类,该类中应包含 String 类型的成员变

6、量brand(商标)和 color(颜色),默认 brand 为 Tiguan,默认 color 值为 White,还应包含成员方法 run(在控制台显示我们已经开动了!哈哈!)和 showInfo(显示信息,在控制台显示商标和颜色),并编写构造方法初始化其成员属性。2、编写 Car(轿车)类继承于 Vehicles 类,增加 int 型成员属性 seats(座位),默认brand,color,seats 的值分别是 Benz,White,7,还应增加成员方法 showCar(显示轿车的信息),并编写构造方法。 3、编写 Truck(卡车)类继承于 Vehicles 类,增加 float 型成

7、员属性 load(载重),默认brand,color ,load 的值分别是 Dongfeng,Blue,100,还应增加成员方法showTruck(在控制台显示卡车的信息),并编写构造方法。 4、建立两个汽车对象,保时捷(Porsche)红色五座轿车,福特(Ford)载重五顿的卡车,并分别输出各自的 brand,color,seats,load 等信息。输出结果格式如下:import java.util.*; public class main protected String brand; protected String color; main(String brand,String c

8、olor) this.brand=brand; this.color=color; main()/默认的构造函数,默认参数为 Benz White / this.brand=Benz; / this.color=White; public void run() System.out.println(我们已经开动了!哈哈!); public void showInfo() System.out.println(车子商标是:+brand+n 车子颜色是:+color); public static void main(String args) main lx=new main(); Car car

9、=new Car(Porsche,Red,5); Truck truck= new Truck(Ford,Black,10); System.out.println(output:); lx.run(); / lx.showInfo(); car.ShowCar(); truck.ShowTruck(); /父类结束 class Car extends main protected int seats; public void ShowCar() / super.showInfo(); System.out.println(轿车商标是:+brand+n 轿车颜色是:+color); Syste

10、m.out.println(轿车座位数是: +seats); Car(String brand,String color,int seats) this.seats=seats; this.brand=brand; this.color=color; Car() this.brand=Benz; this.color=Red; this.seats=5; /默认的座位数为 5 座 /Car 类结束 class Truck extends main protected float load; public void ShowTruck() / this.showInfo(); System.ou

11、t.println(卡车商标是:+brand+n 卡车颜色是:+color); System.out.println(卡车载重是:+load); Truck(String brand,String color,float load) this.brand=brand; this.color=color; this.load=load; Truck() this.brand=Dongfeng; this.color=Blue; load=100; 编写应用程序,求 1!+2!+10!输出结果的格式如下:output:1 到 10 的阶乘之和是:XXXXXpublic class main public static void main(String args) int fact,sum=0; for(int i=1;i=10;i+) fact=1; for(int j=1;j=i;j+) fact*=j; sum+=fact; System.out.println(output:n1 到 10 的阶乘之和是:+sum);

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

当前位置:首页 > 办公文档 > 解决方案

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号