Given the code fragment:
String[] arr = {"A", "B", "C", "D"}; | |
for (int i = 0; i < arr.length; i++) { | |
System.out.print(arr[i] + " "); | |
if (arr[i].equals("C")) { | |
continue; | |
} | |
System.out.println("Work down"); | |
break; | |
} |
What is the result?
A.
A B C Work done
B.
A B C D Work done
C.
A Work done
D. Compilation fails
題解
第一次執行第7行的for迴圈,i為0,arr[i]為A,所以第9行的if條件式不成立,程式執行到第13行的「break;」就直接跳出迴圈。所以只輸出了「A Work done」。