ImageVerifierCode 换一换
格式:DOCX , 页数:16 ,大小:31.12KB ,
资源ID:615639      下载积分:12 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/615639.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(良心出品java编程题.docx)为本站会员(b****1)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

良心出品java编程题.docx

1、良心出品java编程题1. 定义一个包括10个元素一维整型数组,通过从键盘输入的10个整数对数组进行初始化,将数组中的元素按小到大排序后在屏幕上显示,求出该数组中元素的最小值、最大值以及平均值并在屏幕上显示输出。解答:import java.util.Scanner;import java.util.Arrays;public class Testpublic static void main(String args) int x = new int10; double sum =0; Scanner scr = new Scanner(System.in); for(int i=0;ix.l

2、ength;i+) xi= scr.nextInt(); Arrays.sort(x); for(int i=0;ix.length;i+) sum += xi; System.out.println(Max=+xx.length-1); System.out.println(Min=+x0); System.out.println(Average=+sum/x.length); 2.编写一个学生类Student:属性包括:学号(id)、姓名(name)、英语成绩(eng)、数学成绩(math)、计算机成绩(comp)和总成绩(sum)方法包括:构造方法、各属性的set方法、各属性的get方法

3、、toString方法(输出学生的全部信息)、sum方法(计算总成绩)。解答:public class Student implements Serializable /属性定义 public Student(String id,String name,int eng,int math,int comp) this.id=id; this.name=name; this.eng=eng; this.math=math; p=comp; sum(); /计算总成绩 public Student(Student s) this.id=s.id; this.name=new String(s.nam

4、e); this.eng=s.eng; this.math=s.math; p=p; sum(); /计算总成绩 public void setId(String id) this.id=id; public void setName(String name) this.name=name; public void setEng(int eng) this.eng=eng; sum(); public void setMath(int math) this.math=math; sum(); public void setComp(int comp) p=comp; sum(); public

5、 String getId() return id; public String getName() return name; public int getEng() return eng; public int getMath() return math; public int getComp() return comp; public int getSum() return sum; void sum() this.sum=eng+math+comp; public String toString() return getId() + t+getName() + t+getEng() +

6、t+getMath() +t+getComp() + t+getSum(); 3. 设计一个一元二次方程类,并为这个类添加异常处理。解答:public class Operation public static void main(String args) String s=; double a,b,c,r1,r2; System.out.print(求二元一次方程的根) ; System.out.print(请键入第一个系数a) ; try BufferedReader in =new BufferedReader( new InputStreamReader(System.in); s=i

7、n.readLine(); catch(IOException e) a=Double.parseDouble(s); System.out.print(请键入第二个系数b) ; try BufferedReader in =new BufferedReader( new InputStreamReader(System.in); s=in.readLine(); catch(IOException e) b=Double.parseDouble(s); System.out.print(请键入第三个系数c) ; try BufferedReader in =new BufferedReade

8、r( new InputStreamReader(System.in); s=in.readLine(); catch(IOException e) c=Double.parseDouble(s); r1=(-b+Math.sqrt(b*b-4*a*c)/(2*a); r2=(-b-Math.sqrt(b*b-4*a*c)/(2*a); System.out.print(该二元一次方程的根为:+r1+和+r2) ; 4.编写一个应用程序创建两个线程,一个线程打印输出11000之间所有3的倍数,另外一个线程打印输出10002000之间所有5的倍数。解答:class Thread1 extends

9、 Thread public Thread1(String msg) super(msg); public void run() int sum=0; for(int i=1;i=1000;i+) if(i % 3 =0) System.out.println(i); class Thread2 extends Thread public Thread2(String msg) super(msg); public void run() int sum=0; for(int i=1000;i=2000;i+) if(i % 5 =0) System.out.println(i); public

10、 class Exam5 public static void main(String args) Thread1 x = new Thread1(Thread1); Thread2 y = new Thread2(Thread2); x.start(); y.start(); 5.水仙花数是指这样的三位数,其个位、十位和百位三个数的平方和等于这个三位数本身,请编写程序打印输出所有(100999之间)的水仙花数。解答:public class Narcissus public static void main(String args) int i,j,k,n=100,m=1; while (n

11、1000) i=n/100; j=(n-i*100)/10; k=n%10; if(Math.pow(i,3)+Math.pow(j,3)+Math.pow(k,3)=n) System.out.println(找到第+m+ +个水仙花数:+n); n+; m=1; / 或者使用下面的方法 for (n=100;n1000;n+) i=n/100; j=(n-i*100)/10; k=n%10; if(Math.pow(i,3)+Math.pow(j,3)+Math.pow(k,3)=n) System.out.println(找到第+m+ +个水仙花数:+n); n+; 6. 编写程序随机生

12、成10个1到200之间的正整数,打印输出这些随机数并求它们的最大值、最小值、平均值。解答:import java.util.Arrays;public class Test public static void main(String args) int a= new int10; double sum=0; for(int i=0;ia.length;i+) ai=(int)(Math.random()*200+1); sum+=ai; System.out.print(ai+ ); Arrays.sort(a); System.out.println(nmin=+a0); System.o

13、ut.println(max=+aa.length-1); System.out.println(average=+(sum/a.length); 7.按以下要求定义一个类Circle描述一个圆,并完成相应的操作:(1) 实例属性:圆心x坐标(xpoint)、圆心y坐标(ypoint)和半径(radius)。(2) 构造方法:给3个属性赋初值。 (3) 实例方法(area):求圆的面积。(4) 实例方法(circumference):求圆的周长。(5) 重写toString()方法,返回圆心坐标和半径。(6) 实例化这个类,调用方法完成信息的输出。解答:class Circle private double xpoint; private double ypoint; private double radius; public Circle(double x,double y,double r) xpoint = x; ypoint = y; radius = r; public double area() return Math.PI*radius*radius; public double circumference() return 2* Math.PI*radius; public String toString() return 圆心:(+xpoint+,+yp

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1