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

加入VIP,免费下载
 

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

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

下载须知

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

版权提示 | 免责声明

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

编辑一个Java程序.docx

1、编辑一个Java程序1. 编辑一个Java程序,在屏幕上输出两行文本:首先输出你的第一个Java程序名字,然后输出你的名字和编写程序的时间 。 2. 阅读以下程序,判断输出结果 public class Example2_2 public static void main (String args ) int c=2200; long d=8000; float f; double g=123456789.123456789; c=(int)d; f=(float)g; System.out.print(c= +c); System.out.println( d= +d); System.ou

2、t.println(f= +f); System.out.println(g= +g); 3. 编写程序,声明double 的变量r 并赋值, 用 r 存储一个圆半径。计算并输出该园的直径、周长、面积。 public class exe2_3 public static void main(String args) final double pi = 3.14159; double r =6.70,d,peri,area; d = 2*r; peri = pi*d; area = pi*r*r; System.out.println(圆的直径为+d); System.out.println(圆

3、的周长为+peri); System.out.println(圆的面积为+area); 4. 编写程序执行以下的一维数组操作a) 将整数数组counts的 6个元素分别设为16b) 将整数数组bounds的 6个元素分别设为1060c) 将counts元素的值赋值于bounds对应的元素。输出bounds更改前后的各元素的值。 public class exe2_4 public static void main(String args) int counts = 1,2,3,4,5,6; int bounds = 10,20,30,40,50,60; System.out.println(b

4、ounds 更改前各元素的值分别为: + bounds0 +, + bounds1 +, + bounds2 +, + bounds3 +, + bounds4 +, + bounds5); bounds0 = counts0; bounds1 = counts1; bounds2 = counts2; bounds3 = counts3; bounds4 = counts4; bounds5 = counts5; System.out.println(bounds 更改后各元素的值分别为: + bounds0 +, + bounds1 +, + bounds2 +, + bounds3 +,

5、 + bounds4 +, + bounds5); /当你学习循环结构后,你将知道以上代码应该用循环结构!5. 阅读以下程序,判断输出结果 public class Example2_2 public static void main (String args ) int y, x=1,total=0; while( xb) System.out.println(a+ 与+b+ 的最大值是:+a); else System.out.println(a+ 与+b+ 的最大值是:+b); 7. 将三个数按从小到大顺序输出。public class exe3_3 public static void

6、 main(String args) double a =45.90,b=-34.0,c=19.554; double temp; if(ab) temp = a; a = b; b = temp; if(ac) temp = a; a = c; c = temp; if(bc) temp = b; b = c; c = temp; System.out.println(按从小到大顺序输出:+a+, +b+, +c); 8. 编写程序计算1+3+5+.+99。 public class exe3_4 public static void main(String args) int res=0;

7、 for (int i=1;i100;i+=2) res += i; System.out.println (1+3+5+.+99 = +res); 9. 编写程序计算输出十个数中的最小值,。public class exe3_5 public static void main(String args) int a = 49,67,24,567,57,3,46,89569,98,100; int i,min; min = a0; i = 1; while(iai) min = ai; i+; System.out.println(the minimum is: +min); 10. 计算 1/

8、1! + 1/2! + 1/3! + .+ 1/20! public class exe3_6 public static void main(String args) int product=1, i=1; float sum=0.0f; while(i=20) product *= i; sum += 1.0/product; i+; System.out.println(sum=+sum); 11. 计算 Fibonacci 序列的前20项。public class exe3_7 public static void main(String args) int Fib = new int

9、20; Fib0 = 0; Fib1 = 1; for(int i=2;i20;i+) Fibi = Fibi-1+Fibi-2; System.out.println(Fibonacci 序列:); for(int i=0;i20;i+) System.out.print(Fibi+ ); 12. P.100 3,7,13 class Max static int calMax(int arr) int max; max = arr0; for(int i=1;iarr.length;i+) if(maxarri) max = arri; return max; class exe4_3 p

10、ublic static void main(String args) int a =34,20,-34,890,34,234,4; System.out.println(最大值为: +Max.calMax(a); 13. 创建SavingAccount类。用静态变量annualInterestRate 存储年利息率。用私有实例变量savingBalance存储账户当前的余额。提供方法calculateMonthlyInterest计算 月利息。即将savingBalance乘以annualInterestRate ,然后除以12. 提供一个静态方法modifyInterestRate,将an

11、nualInterestRate设置一个新值。 编写一个测试程序测试 SavingAccount类.实例化两个SavingAccount 对象:saver1 和 save2,它们的余额分别是¥2000.00 和 3000.00.将annualInterestRate 设置为4%, 计算两个账户的月利息,并打印每个账户的新存款余额。然后将annualInterestRate 设置为5%, 计算两个账户的月利息,并打印每个账户的新存款余额 class SavingAccount static float annulInterestRate; private float savingBalance;

12、 public SavingAccount(float balance) savingBalance = balance; float calculateMonthlyInterest() return annulInterestRate*savingBalance/12; static void modifyInterestRate(float rate) annulInterestRate = rate; class exe4_5 public static void main(String args) float balance1 = 3000.00f, balance2 = 4000.

13、00f; SavingAccount saver1 = new SavingAccount(balance1); SavingAccount saver2 = new SavingAccount(balance2); SavingAccount.annulInterestRate =0.04f; System.out.println(当年利率为4%:); System.out.println( 第一个账户月利息为 + saver1.calculateMonthlyInterest() + , 1年后账户的存款余额为 +balance1*(1+SavingAccount.annulInteres

14、tRate); System.out.println( 第二个账户月利息为 + saver2.calculateMonthlyInterest() + , 1年后账户的存款余额为 +balance2*(1+SavingAccount.annulInterestRate); SavingAccount.modifyInterestRate(0.05f); System.out.println(当年利率为5%:); System.out.println( 第一个账户月利息为 + saver1.calculateMonthlyInterest() + , 1年后账户的存款余额为 +balance1*

15、(1+SavingAccount.annulInterestRate); System.out.println( 第二个账户月利息为 + saver2.calculateMonthlyInterest() + , 1年后账户的存款余额为 +balance2*(1+SavingAccount.annulInterestRate); 14. 模仿课堂讲解的例题, 编写 Bus 类 和 Cinema 类,它们继承两个接口,一个关于收费,另一个是调节温度 interface fee public void fee();interface controlTemperature public void a

16、irContr();class Bus implements fee,controlTemperature public void fee() System.out.println(bus: $1 per ticket,not considering the distance); public void airContr() System.out.println(air-conditioner A installed in a bus); class Cinema implements fee,controlTemperature public void fee() System.out.pr

17、intln(Cinema: $5 per ticket); public void airContr() System.out.println( air-conditioner B installed in a cinema); class exe4_6 public static void main(String args) Bus bus_obj = new Bus(); Cinema cinema_obj = new Cinema(); bus_obj.fee(); bus_obj.airContr(); cinema_obj.fee(); cinema_obj.airContr();

18、15. p.100 18 class maxComDivisor /* * purpose: calculate the maximumal common divisor of two numbers */ public int f(int a, int b) if(ab) int temp; temp = a; a = b; b = temp; int r = a%b; while(r!=0) a = b; b = r; r = a % b; return b; class leastComMultiple extends maxComDivisor /* * purpose: calcul

19、ate the least commom multiple of two numbers */ public int f(int a, int b) int m; m = a*b/super.f(a,b); return m; public class exe4_8 public static void main(String args) int x,y; x = Integer.parseInt(args0); y = Integer.parseInt(args1); maxComDivisor obj1 = new maxComDivisor(); System.out.println(t

20、he maximumal common divisor of +x+ and +y+ = + obj1.f(x,y); leastComMultiple obj2 = new leastComMultiple(); System.out.println(the least common multiple of +x+ and +y+ = + obj2.f(x,y); 16. 从键盘输入若干名同学的数学成绩,计算总成绩和平均成绩. 17. 将一组字符串按字典顺序重新排序 “England”,“China”, ”America”, ”Canada”,”Turkey” 18. 从键盘输入一个日期(字

21、符串格式:yyyy-mm-dd),计算80天后的年、月、日和星期。 19. P.118 1, 3 (自学String 类的方法 toUpperCase() toLowerCase(), charAt(int index) 20. P.211 6 21. 编写一个用户注册界面。并把用户的输入信息在文本区中显示。22. P.225 1 23. 阅读以下程序,判断输出结果 public class Example2_2 public static void main (String args ) int y, x=1,total=0; while( x= 10 ) y = x*x; System.out.print(y); total += y ; x+; System.out.println(Total is + total); 24. 编写程序计算输出两个数的最大值。 25. 将三个数按从小到大顺序输出。 26. 编写程序计算1+3+5+.+99。 27. 编写程序计算输出十个数中的最小值,。 28. 计算 1/1! + 1/2! + 1/3! + .+ 1/20! 29. 计算 Fibonacci 序列的前20项。 30. 编制一个学生管理程序。学生信息存储在数据库表中。每个学生信息包括学号、姓名以及数学、英语和物理成绩。要求具有显示所有学生信息和增加新的学生信息等功能。

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

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