So, basically I need to print out a 2d array as a table and put indexes "around" it.
Random rnd = new Random();
int[][] array = new int[5][5];
for (int row = 0; row < array.length; row++) {
for (int col = 0; col < array[row].length; col++) {
array[row][col] = rnd.nextInt(6);
}
}
for (int row = 0; row < array.length; row++) {
for (int col = 0; col < array[row].length; col++) {
if (col < 1) {
System.out.print(row+" ");
System.out.print(" " + array[row][col] + " ");
} else {
System.out.print(" " + array[row][col] + " ");
}
}
System.out.println();
}
}
I get this:
0 2 4 0 2 4
1 1 2 0 2 2
2 0 1 5 4 0
3 4 2 1 4 1
4 2 4 3 1 3
So the first (left) column are indexes and I need to put another column of indexes (0,1,2,3,4) on top of the "table" with "counting" starting from the second column...something like this:
0 1 2 3 4
0 2 4 0 2 4
1 1 2 0 2 2
2 0 1 5 4 0
3 4 2 1 4 1
4 2 4 3 1 3
Sorry for any mistakes, its my first time asking here.