好吧,所以我告訴有一個輕微的邏輯錯誤與我的內循環。顯然如果我的[2] [2]數組是2X3元素或3X2元素,它不會工作有人可以告訴我如何解決這個小問題?邏輯錯誤與循環陣列
public static void dispArr(String [][] country){
for(int i= 0; i<country.length; i++){ // both for loops count from 0 to 1 which are the only numbers required for this given array
for(int j= 0; j<country.length; j++){
System.out.print(country[i][j]); //this will output [0][0],[0][1],[1][0] and[1][1] as identified above.
}
System.out.println("\n"); //create space between both
}
}
在內部循環中試試'country [i] .length' –
非常感謝大家! – user3111329