Given:
22. public void go(){
23. String o = "";
24. z:
25. for(int x=0; x<3; x++){
26. for(int y=0; y<2; y++){
27. if(x == 1) break;
28. if(x==2 && y==1) break z;
29. o = o + x + y;
30. }
31. }
32. System.out.println(o);
33. }
What is the result when the go() method is invoked?
A. 00
B. 0001
C. 000120
D. 00012021
E. Compilation fails.
F. An exception is thrown at runtime.——————————————————————————————————————————————————————
Given:
1. public class Breaker{
2. static String o = "";
3. public static void main(String[] args){
4. z:
5. o = o + 2;
6. for(int x=3; x<8; x++){
7. if(x == 4) break;
8. if(x == 6) break z;
9. o = o + x;
10. }
11. System.out.println(o);
12. }
13. }
What is the result?
A. 23
B. 234
C. 235
D. 2345
E. 2357
F. 23457
G. Compilation fails.——————————————————————————————————————————————————Given:
1. public class Breaker2{
2. static String o = "";
3. public static void main(String[] args){
4. z:
5. for(int x=2; x<7; x++){
6. if(x == 3) continue;
7. if(x == 5) break z;
8. o = o + x;
9. }
10. System.out.println(o);
11. }
12. }
What is the result?
A. 2
B. 24
C. 234
D. 246
E. 2346
F. Compilation fails.不是很明白当中的  z: 指的是啥?当时就蒙了!!当然上机就能得出答案,望高手说明原因!谢谢

解决方案 »

  1.   

    标号。
    可以看看下面的这个
    http://jgs80.blog.163.com/blog/static/3566265320069410175599/
      

  2.   

    这儿的break o;是退出o所包围的代码块或者循环
      

  3.   

    我也刚试了下,的确是!谢谢提醒!!!经修改:public class Test{
     static String o = "";
     public static void main(String[] args){
    z:{
     o = o + 2;
    for(int x=3; x<8; x++){
      if(x == 4) break;
      if(x == 6) break z;
      o = o + x;
    }
     System.out.println(o);
     }
     }
    }
      

  4.   

    引用 2 楼 huayuanzzb 的回复:
    楼主,第二段代码,编译时通过不了的上面的括号位置不对参考下边这个
    我也刚试了下,的确是!谢谢提醒!!!经修改:public class Test{
     static String o = "";
     public static void main(String[] args){
    z:{
     o = o + 2;
    for(int x=3; x<8; x++){
      if(x == 4) break;
      if(x == 6) break z;
      o = o + x;
    }}
     System.out.println(o);
     }
     }