全文预览已结束
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
写出下列程序运行的结果1public class SignFunction public static void main(String args) int intx; intx=0; if(intx0) System.out.println(The sign of +intx+ is + ;); else if(intx0) System.out.println(The sign of +intx+ is - ;); else System.out.println(The sign of +intx+ is 0 ;); 程序执行结果为:( 0 );2 /Sum.java源代码如下:public class Sumpublic static void main(String args)int j=10;System.out.println(j is : +j);calculate(j);System.out.println(At last,j is : +j);static void calculate(int j)for (int i=0;i10;i+)j+;System.out.println(j in calculate() is: +j);输出结果为:j is : (1) j in calculate() is :(2) At last j is : (3) 答案: j is : 10j in calculate() is: 20At last,j is : 103class UseArrayCopypublic static void main(String args) int a=1,2,3,4,5,6,7; int b=new int6; int i; System.arraycopy(a,1,b,2,3); for(i=0;i= 90) grade = A; else if (score = 80) rade = B; else if (score = 70) grade = C; else if (score = 60) grade = D; else grade = E; System.out.println(Grade = + grade); 程序执行结果为:( Grade = B );5处理除数为0的异常public class UserExceptionDemo1public static void main(String args) int a,b; try a=10;b=0; int c=Divide(a,b); System.out.println(a+/+b+=+c); catch(ArithmeticException e) System.out.println(Divided by zero error!); System.out.println(After try-catch.);static int Divide(int x,int y) return x/y;程序运行结果为:( Divided by zero error!After try-catch. );五、程序阅读填空1、完成求n!的程序public class Testpublic static void main(String args) factorial(3);factorial(6);factorial(9);static (1) factorial(int n)long m=1;for (int x=1;x=n; (2) ) (3) ;System.out.println(n+!=+m);六、编程题1使用dowhile循环,计算1至2000之间的所有奇数的和。解:static int Divide() int i = 1; / i初始值为1int sum = 0;do sum += i;i += 2; while (i 2000);return sum;2编程将字符串Mary was a改为Mary had a book.。 StringBuffer str1=new StringBuffer(Mary was a); StringBuffer str2=str1.replace(5,10,had a book.); System.out.println(str2);3计算1!+2!+3!+10!。int i;long j = 1, s = 0;for (i = 1; i = 10; i+) j *= i;s += j;System.out.println(s);4编写一个程序,用选择法对数组a=20,10,50,40,30,70,60,80,90,100进行从大到小的排序。int a = 20, 10, 50, 40, 30, 70, 60, 80, 90, 100 ;int i, n, max;for (i = 0; i = 8; i+) for (n = i + 1; n = 9; n+) if (ai an) max = ai;ai = an;an = max;for (i = 0; i = 9; i+) System.out.print(ai + );5输出九九乘法表。int i
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025影视拍摄设备市场发展分析及前景趋势与商业机会研究报告
- 2025年一建矿业工程管理与实务试卷含答案
- 2025工业视觉检测算法泛化能力提升与迁移学习应用分析报告
- 2025工业机器人行业市场发展分析及前景趋势与资本运作机会研究报告
- 2025工业机器人市场发展分析及智能化趋势与投资机会研究报告
- 2025土壤修复技术路线比较与政策支持效果评估
- 2025固态电池技术路线对比分析及车企战略布局与产业投资窗口期报告
- 2025商旅行业竞争格局与未来投资战略规划研究报告
- 2025咖啡行业市场渗透率提升与商业模式创新研究报告
- 2025可穿戴生物识别设备市场需求与竞争格局研究报告
- 《横断面研究调查》课件
- GB/T 42535-2023锅炉定期检验
- 年产30万吨合成氨工艺合成工段设计
- 脚手架工程监理实施细则 (盘扣式脚手架)正式版
- 2021年律师所行业调查研究报告
- 红旗杯班组长题库
- GB/T 3469-1983文献类型与文献载体代码
- GA 1551.6-2021石油石化系统治安反恐防范要求第6部分:石油天然气管道企业
- 食品冷冻-课件
- 合成氨企业安全生产安全生产双控方案全套资料方案风险分级管控和隐患排查治理全套资料汇编完整版
- 固相膜免疫分析技术技术课件
评论
0/150
提交评论