SCJP題庫第006題


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.

Ans: G

解說:
break 後面的地標z必須緊跟著迴圈,以此例來說,z必須後面緊接著for
public class Breaker{
  static String o = "";
  public static void main(String[] args){
    o = o + 2;
    z:
    for(int x=3; x<8; x++){
if(x == 4) break;
if(x == 6) break z;
o = o + x;
    }
    System.out.println(o);
  }
}

Comments

Popular posts from this blog

Android+Google Map API v3 Geocoding(地址轉經緯度度