-流程控制、异常和断言-有关断言的题不用做_第1页
-流程控制、异常和断言-有关断言的题不用做_第2页
-流程控制、异常和断言-有关断言的题不用做_第3页
-流程控制、异常和断言-有关断言的题不用做_第4页
-流程控制、异常和断言-有关断言的题不用做_第5页
已阅读5页,还剩7页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

内容概要练习u 流程控制 (if 和 switch) 1. 给出以下代码: 1. public class Switch2 2. final static short x = 2; 3. public static int y = 0; 4. public static void main(String args) 5. for (int z=0; z 3; z+) 6. switch (z) 7. case y: System.out.print(0 ); 8. case x-1: System.out.print(1 ); 9. case x: System.out.print(2 ); 10. 11. 12. 13. 哪一项是运行结果? A. 0 1 2 B. 0 1 2 1 2 2 C. 在第7行编译失败。 D. 在第8行编译失败。 E. 在第9行编译失败。 F. 运行时抛出异常。 2. 给出下面的代码: 1. public class Switch2 2. final static short x = 2; 3. public static int y = 0; 4. public static void main(String args) 5. for (int z=0; z 3; z+) 6. switch (z) 7. case x: System.out.print(0 ); 8. case x-1: System.out.print(1 ); 9. case x-2: System.out.print(2 ); 10. 11. 12. 13. 哪一项是运行结果? (1)A. 0 1 2 B. 0 1 2 1 2 2 C. 2 1 0 1 0 0 D. 2 1 2 0 1 2 E. 在第8行编译失败。 F. 在第9行编译失败。 3. 给出下面的代码: 1. public class If1 2. static boolean b; 3. public static void main(String args) 4. short hand = 42; 5. if ( hand 50 ) ; 7. else if ( hand 40 ) 8. hand += 7; 9. hand+; 10. else 11. -hand; 12. System.out.println(hand); 13. 14. 哪一项是运行结果 A. 41 B. 42 C. 50 D. 51 E. 在第5行编译失败。 F. 在第6行编译失败。 4. Given the following, 1. public class Switch2 2. final static short x = 2; 3. public static int y = 0; 4. public static void main(String args) 5. for (int z=0; z 6 ) 10. x+; 11. 12. if ( !b1 ) x = x + 10; 13. else if ( b2 = true ) x = x + 100; 14. else if ( b1 | b2 ) x = x + 1000; 15. 16. 17. System.out.println(x); 18. 19. 哪一项是运行结果? A. 0 B. 1 C. 101 D. 111 E. 1001 F. 1101 u 流程控制(循环) 6. 给出下面的代码: 1. public class While 2. public void loop() 3. int x= 0; 4. while ( 1 ) 5. System.out.print(x plus one is + (x + 1); 6. 7. 8. 哪一项是正确的? A. 在第1行有一个语法错误。 B. 在第1行和第4行有一个语法错误。C. 在第1行、第4行和第5行有一个语法错误。 D. 在第4行有一个语法错误。 E. 在第4行和第5行有一个语法错误。 F. 在第5行有一个语法错误。 7. 给出下面的代码: 1. class For 2. public void test() 3. 4. System.out.println(x = + x); 5. 6. 7. and the following output, x = 0 x = 1 哪两行语句独立地插入到第3行能够产生输出? A. for (int x = -1; x 2; +x) B. for (int x = 1; x 2; +x ) D. for (int x = 0; x 2; x+ ) E. for (int x = 0; x 2; +x ) 8. 给出以下代码: 1. public class Test 2. public static void main(String args) 3. int I = 1; 4. do while ( I 1 ) ; 7. 8. 哪一项是运行结果? A. I is 1 B. I is 1 I is 1 C. 没有输出。 D. 编译错误。 E. I is 1 I is 1 I is 1 in an infinite loop. 9. 给出下面的代码: 11. int I = 0; 12. outer: 13. while (true) 14. I+; 15. inner: 16. for (int j = 0; j 10; j+) 17. I += j; 18. if (j = 3) 19. continue inner; 20. break outer; 21. 22. continue outer; 23. 24. System.out.println(I); 25. 26. 哪一项是运行结果?(1) A. 1 B. 2 C. 3 D. 4 10. 给出下面的代码: 1. int I = 0; 2. label: 3. if (I 0 : bar(7); 14. assert t 1 : foo(8); 15. System.out.println(done ); 16. 17. 哪一项是运行的结果? A. bar B. bar done C. foo done D. bar foo done E. 编译失败。 F. 运行时抛出异常。 19. 下面哪两项是正确的? A. 包含断言语句的程序在运行时不加参数,缺省情况下断言语句将被执行。B. 在Java1.4版本中,缺省情况下断言语句能够被编译。 C. 正确地使用运行时参数,可以指示虚拟机关闭某一个类中的断言同时打开某一个包中的断言。D. 下面都是合法的运行时断言标志: -ea, -esa, -dsa, -enableassertions, -disablesystemassertions E. 虚拟机在处理命令行参数时,对ea标志的处理会优先于da标志。 20. 给出下面的代码: 1. public class Test2 2. public static int x; 3. public static int foo(int y) 4. return y * 2; 5. 6. public static void main(String args) 7. int z = 5; 8. assert z 0; 9. assert z 2: foo(z); 10. if ( z 4; 12. switch (z) 13. case 4: System.out.println(4 ); 14. case

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论