JAVA编程题全集(100题答案)w

上传人:mg****2 文档编号:121916611 上传时间:2020-02-28 格式:DOC 页数:18 大小:80KB
返回 下载 相关 举报
JAVA编程题全集(100题答案)w_第1页
第1页 / 共18页
JAVA编程题全集(100题答案)w_第2页
第2页 / 共18页
JAVA编程题全集(100题答案)w_第3页
第3页 / 共18页
JAVA编程题全集(100题答案)w_第4页
第4页 / 共18页
JAVA编程题全集(100题答案)w_第5页
第5页 / 共18页
点击查看更多>>
资源描述

《JAVA编程题全集(100题答案)w》由会员分享,可在线阅读,更多相关《JAVA编程题全集(100题答案)w(18页珍藏版)》请在金锄头文库上搜索。

1、 . Java程序设计总复习题1、 编写一个Java程序,用if-else语句判断某年份是否为闰年。(分支)/ Programme Name LeapYear.javapublic class LeapYearpublic static void main(String args)int year=2010; if(args.length!=0) year=Integer.parseInt(args0);if(year%4=0 & year%100!=0)|(year%400=0) System.out.println(year+ 年是闰年。);else System.out.println(

2、year+ 年不是闰年。); /if-else语句2、 编写一个Java程序在屏幕上输出1!+2!+3!+10!的和。(循环)/ programme name ForTest.javapublic class ForTest public static void main( String args ) int i,j,mul,sum=0;for(i=1;i=10;i+) mul=1;for(j=1,j=i;j+) mul=mul*j; sum=sum+mul;System.out.println(“1!+2!+3!+10!= ”+sum);3、 依次输入10个学生成绩,判断学生(优秀、良好、中

3、等、及格、不及格)并计算人数(switch)4、 使用冒泡排序(数组)public class BubbleSort public static void main(String args) int array=63,4,24,1,3,5;BubbleSort sorter=new BubbleSort();sorter.sort(array);/冒泡排序public void sort(int array)for(int i=1;iarray.length;i+)for(int j=0;jarrayj+1)int temp=arrayj;arrayj=arrayj+1;arrayj+1=te

4、mp; showArray(array);/遍历数组,并输出数组的元素。public void showArray(int array)for(int i=0;iarray.length;i+) System.out.print(arrayi+t);System.out.println();5、 实现会员注册,要求用户名长度不小于3,密码长度不小于6,注册时两次输入密码必须相同 (字符串)import java.util.Scanner;public class Register String name;String password;String newPassword;/public vo

5、id nameExe()Scanner input=new Scanner(System.in);System.out.println(请输入用户名,密码和验证密码); System.out.print(用户名:); name=input.next(); System.out.print(密码:); password=input.next(); System.out.print(验证密码:); newPassword=input.next();while(name.length()3|(password.equals(newPassword)=false)|(password.length()

6、6)if(name.length()3)System.out.println(用户名不能小于3);if(password.equals(newPassword)=false)|password.length()0&age12) ticketPrice=20; else if(age20) ticketPrice=40; else if(age50) ticketPrice=80; else ticketPrice=35; System.out.println(门票价格:+ticketPrice); /import java.util.Scanner;public class Test publ

7、ic static void main(String args) Scanner input=new Scanner(System.in);Tourist t1=new Tourist();System.out.print(请输入年龄:);t1.setAge(input.nextInt();t1.ticket(); 7、 (1)编写一个圆类Circle,该类拥有:一个成员变量Radius(私有,浮点型); / 存放圆的半径; 两个构造方法 Circle( ) / 将半径设为0 Circle(double r ) /创建Circle对象时将半径初始化为r 三个成员方法 double getAre

8、a( ) /获取圆的面积 double getPerimeter( ) /获取圆的周长 void show( ) /将圆的半径、周长、面积输出到屏幕(2)编写一个圆柱体类Cylinder,它继承于上面的Circle类。还拥有:一个成员变量double hight(私有,浮点型); / 圆柱体的高; 构造方法 Cylinder (double r, double h ) /创建Circle对象时将半径初始化为r 成员方法 double getVolume( ) /获取圆柱体的体积 void showVolume( ) /将圆柱体的体积输出到屏幕编写应用程序,创建类的对象,分别设置圆的半径、圆柱体

9、的高,计算并分别显示圆半径、圆面积、圆周长,圆柱体的体积。/Programme Name TestCylinder.java class Circle /定义父类-园类private double radius; /成员变量-园半径Circle() /构造方法radius=0.0;Circle(double r) /构造方法 radius=r; double getPerimeter() /成员方法-求园周长return 2*Math.PI*radius;double getArea() /成员方法-求园面积return Math.PI*radius*radius;void disp() /成

10、员方法-显示园半径、周长、面积System.out.println(圆半径=+radius);System.out.println(圆周长=+getPerimeter();System.out.println(圆面积=+getArea();class Cylinder extends Circle /定义子类-圆柱类private double hight; /成员变量-园柱高Cylinder(double r,double h) /构造方法 super(r);hight=h;public double getVol() /成员方法-求园柱体积return getArea()*hight;public void dispVol() /成员方法-显示园柱体积System.out.println(圆柱体积=+getVol();public class TestCylinder /定义主类public static void main(String args) /主程入口

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 办公文档 > 教学/培训

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