将以下程序段重新排列,使其成为可以编译与执行的程序,并能输出以下结果: % 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-03-04 11:51:48 浏览: 155
以下是重新排列后的程序段:
1. class MyEx extends Exception{}
2. public static void main(String[] args){
3. String test = args[0];
4. String yes = "yes";
5. String no = "no";
6. String t = "throws";
7. String s = "thaws";
8. String w = "w";
9. String a = "a";
10. String h = "h";
11. String r = "";
12. String o = "o";
13. try{
14. System.out.print(w);
15. if(yes.equals(test)){
16. System.out.print(a);
17. throw new MyEx();
18. }else if(no.equals(test)){
19. System.out.print(o);
20. throw new Exception();
21. }
22. System.out.print(r);
23. doRisky(test);
24. }catch(MyEx e){
25. System.out.print(t);
26. }catch(Exception e){
27. System.out.print(s);
28. }finally{
29. System.out.print(o);
30. }
31.}
32. static void doRisky(String t) throws MyEx{
33. System.out.print(h);
34. }
输出结果:
若执行命令 "java ExTestDrive yes thaws",输出结果为 "wathrowso";
若执行命令 "java ExTestDrive no throws",输出结果为 "wothrowso"。
阅读全文