您好,我的二维数组列正在打印两次。请帮助我识别错误的代码。以下是我尝试过的:
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();
}
}
}
这让我发疯,我似乎找不到错误:(