I'm practicing Java and I got this and I don't know where and how to continue:
- Creates a matrix with user-defined dimensions.
- Fills the matrix with increasing values from top to bottom, left to right.
- Print the status of the matrix.
The result that I have to achieve should look like this 5x5
:
0 5 10 15 20
1 6 11 16 21
2 7 12 17 22
3 8 13 18 23
4 9 14 19 24
or this 7x2
:
0 7
1 8
2 9
3 10
4 11
5 12
6 13
This is what I done:
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int count = 0;
System.out.print("Insert rows [i] : ");
int i = in.nextInt();
in.nextLine();
System.out.println("Insert columns [j] : ");
int j = in.nextInt();
in.nextLine();
int[][] matrix = new int[i][j];
for (int k = 0; k < matrix.length; k++) {
for (int l = 0; l < matrix[i].length; l++) {
matrix[i][j] = count;
count++;
}
}
}