4 流程控制、异常和断言_有关断言的题不用做

上传人:cn****1 文档编号:495041242 上传时间:2023-12-31 格式:DOCX 页数:11 大小:346.85KB
返回 下载 相关 举报
4 流程控制、异常和断言_有关断言的题不用做_第1页
第1页 / 共11页
4 流程控制、异常和断言_有关断言的题不用做_第2页
第2页 / 共11页
4 流程控制、异常和断言_有关断言的题不用做_第3页
第3页 / 共11页
4 流程控制、异常和断言_有关断言的题不用做_第4页
第4页 / 共11页
4 流程控制、异常和断言_有关断言的题不用做_第5页
第5页 / 共11页
点击查看更多>>
资源描述

《4 流程控制、异常和断言_有关断言的题不用做》由会员分享,可在线阅读,更多相关《4 流程控制、异常和断言_有关断言的题不用做(11页珍藏版)》请在金锄头文库上搜索。

1、内容概要练习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 );

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.prin

3、t(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

4、. 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 st

5、atic 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 W

6、hile 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

7、(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

8、) ; 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

9、; 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 2) 4. System.out.print(I is + I); 5. I+; 6. continue label; 7. 哪一项是运行的结果?A. I is 0 B. I is 0 I is 1 C. 编译错误。 D.以上都不对。 u 异常11. 给出下面的代码: 1. System.out.print(Start ); 2. try 3. System

10、.out.print(Hello world); 4. throw new FileNotFoundException(); 5. try 6. out = new FileOutputStream(test.txt); 7. out.write(122); 8. 9. catch(IOException io) 10. System.out.println(IO Error.); 11. 12. finally 13. out.close(); 14. 15. 16. 下面哪一项是正确的?A. 程序将成功编译。 B. 第4行有一个错误。 C. 第6行有一个错误。D. 第9行有一个错误。E.

11、第13行有一个错误。14. 给出下面的代码: 1. public class MyProgram 2. public static void throwit() 3. throw new RuntimeException(); 4. 5. public static void main(String args) 6. try 7. System.out.println(Hello world ); 8. throwit(); 9. System.out.println(Done with try block ); 10. 11. finally 12. System.out.println(F

12、inally executing ); 13. 14. 15. 哪一项是正确的?(1) A. 程序不能编译。 B. 程序将输出:Hello world, 然后将输出:a RuntimeException has occurred, 然后将输出:Done with try block, 最后将输出:Finally executing。 C. 程序将输出:Hello world, 然后将输出:a RuntimeException has occurred,最后将输出:Finally executing。D. 程序将输出:Hello world, 然后将输出:Finally executing, 最后将输出:a RuntimeException

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 建筑/环境 > 施工组织

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