I have 2 two-dimensional arrays of integers (the same numbers are placed in the same index spots). They're both using enhanced for loops to print their tables, but they don't print the same.
package randomExperiments; import java.util.Scanner; import java.util.Arrays; import java.util.Random; import java.lang.StringBuilder; import java.text.DecimalFormat; import static randomExperiments.StaticMethodExample.*; public class RandomExperiments { public static void main(String[] args){ //Two dimensional array: int rowCount = 2, columnCount = 4; int[][] numsTable = new int[rowCount][columnCount]; numsTable[0][0] = 9; numsTable[0][1] = 7; numsTable[0][2] = 0; numsTable[0][3] = 3; numsTable[1][0] = 4; numsTable[1][1] = 0; numsTable[1][2] = 3; numsTable[1][3] = 1; //In one statement: int[][] numsTableAgain = { {9,7}, {0,3}, {4,0}, {3,1} }; for(int[] row : numsTable) { for(int column : row) {//for each column of the current row System.out.print("[" + column + "]" + " "); } System.out.println("\n"); } for(int[] row : numsTableAgain) { for(int column : row) {//for each column of the current row System.out.print("[" + column + "]" + " "); } System.out.println("\n"); } } }
The output in the console looks like this:
[9] [7] [0] [3]
[4] [0] [3] [1]
[9] [7]
[0] [3]
[4] [0]
[3] [1]
Why does one print a 2x4 table, and the other print a 4x2 table? Is it possible to make them both print a 2x4 table?