Examly題庫立即開始練習
關務人員考試關務四等-資訊處理(選試英文)科別計算機概要11428單選題

若執行下列的 Java 程式碼,則螢幕上的輸出結果為何? public class ArrayTest{ public static void main(String[] args){ int[][] intArray = {{1, 2, 3, 4}, {5, 6, 7, 8}}; for(int i=0; i<intArray.length; i++){ for(int j=intArray[i].length; j>0; j--){ if (j<=2){ continue; } else { System.out.println(intArray[i][intArray[i].length-j]); } } } } }

A1 5
B1 2 5 6正確答案
C1 2 3 5 6 7
D1 2 3 4 5 6 7 8
答案與詳解
B
正確答案
本題考查 Java 巢狀迴圈、陣列長度與 continue 指令。內層迴圈當 j=4, 3 時印出陣列前兩個元素,j=2, 1 時因 continue 跳過,故輸出 1, 2, 5, 6。

為什麼答案是 B

i=0 時,j=4, 3 印出 intArray[0][0] 與 [0][1] (即 1, 2);i=1 時,j=4, 3 印出 intArray[1][0] 與 [1][1] (即 5, 6)。j=2, 1 時皆因 continue 跳過。

考點:迴圈執行次數考點:陣列與迴圈追蹤考點:continue 控制考點:條件判斷
載入中…

計算機概要 相關題目

想練更多計算機概要考古題?

Examly 收錄 38 萬+ 道歷屆題目,每題都有像這樣的精選詳解。免費下載,立即開練。

Download on theApp Store即將推出Google Play
黑皮