将以下程序段重新排列,使其成为可以编译与执行的程序,并能输出以下结果: % java ExTestDrive yes thaws % java ExTestDrive no throws 程序段: 1. System.out.print(r); 2. try{ 3. System.out.print(t); 4. doRisky(test); 5. }finally{ 6. System.out.println(s); 7. System.out.print(o); 8. class MyEx extends Exception{} public class ExTestDrive{ 9. System.out.print(w); 10.if(yes.equals(t)){ 11.System.out.print(a);12.throw new MyEx();13.}catch(MyEx e{14.static void doRisky(String t) throw MyEx{ System.out.print(h); 15.public static void main(String[] args){ String test = args[0];
时间: 2024-02-29 19:54:20 浏览: 98
如何制作Java可执行程序
以下是重新排列后的程序段:
1. class MyEx extends Exception{}
2.
3. public static void main(String[] args) {
4. String test = args[0];
5. try {
6. System.out.print("t");
7. doRisky(test);
8. System.out.print("o");
9. } catch (MyEx e) {
10. System.out.print("a");
11. } finally {
12. System.out.print("s");
13. System.out.print("h");
14. System.out.print("w");
15. }
16. }
17.
18. static void doRisky(String t) throws MyEx {
19. System.out.print("h");
20. if ("yes".equals(t)) {
21. throw new MyEx();
22. }
23. System.out.print("r");
24. }
输出结果:
- 当运行 "java ExTestDrive yes thaws" 时,输出 "thawsarshw"
- 当运行 "java ExTestDrive no throws" 时,输出 "throwsorshw"
阅读全文