I am trying to create a 6x3 matrix that increases by one each time as you iterate over the column first and the row second.
This is the code, which I currently have:
public static void main(String[] arg) { int[][] mat1 = new int[6][3]; for(int i = 1; i < mat1.length; i++) { for(int j = 0; j < mat1[i].length; j++) { mat1[i][j] = i + j; System.out.print(mat1[i][j] + " "); } System.out.println(); } } Right now I am getting the output:
1 2 3 2 3 4 3 4 5 4 5 6 5 6 7 The desired output is:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 How would I go about doing this?
int i = 0? Your output is currently missing a row.