你好,我的二維數組列打印兩次。請幫我找出錯誤的代碼。下面是我曾嘗試:Java二維數組列打印兩次
public class ArrayExercise {
public static void main(String[] args){
String[][] myArray = {
{"Philippines", "South Korea", "Japan", "Israel"}, // Countries
{"Manila", "Seoul", "Tokyo", "Jerusalem" } // capital cities
};
String outputString = String.format("%16s\t%9s", "Country", "City");
System.out.println(outputString);
for(int col = 0; col < myArray[0].length; ++col){
for(int row = 0; row < myArray.length; ++row){
System.out.printf("%16s\t%9s", myArray[0][col], myArray[1][col] );
}
System.out.println();
}
}
}
它的駕駛我堅果,我似乎無法找到錯誤:(
刪除內部for循環...而你剛纔問這個問題剛纔?我以爲你的疑問很清楚.. –
再次感謝@RohitJain! –