SCJP(OCPJP) 考古題解析 第7題

Given:

public class Breaker2 {
    static String o = "";
    public static void main(String[] args) {
        z: 
        for (int x = 2; x < 7; x++) {
            if (x == 3) continue;
            if (x == 5) break z;
            o = o + x;
        }
        System.out.println(o);
    }
}


What is the result? 


A. 2
B. 24
C. 234
D. 246
E. 2346
F. Compilation fails.

答案:


解析: 















break:跳到區塊的外面

continue:跳到區塊的末端





0 意見:

張貼留言