I am currently working on an online coding class and I am wondering how instead of manually achieving the answer, how can I use a loop to be more efficient because a worksheet has the following question:
Given:
int[][] values = new int[4][5]
Write a nested loop to set values as follows:[0] [1] [2] [3] [4] [0] 1 2 3 4 5 [1] 1 2 3 4 5 [2] 1 2 3 4 5 [3] 1 2 3 4 5
The following code I have is:
int table[][] = new int [4][5];
table[0][0] = 0;
table[0][1] = 1;
table[0][2] = 2;
table[0][3] = 3;
table[0][4] = 4;
table[1][0] = 1;
table[1][1] = 2;
table[1][2] = 3;
table[1][3] = 4;
table[1][4] = 5;
table[2][0] = 1;
table[2][1] = 2;
table[2][2] = 3;
table[2][3] = 4;
table[2][4] = 5;
table[3][0] = 1;
table[3][1] = 2;
table[3][2] = 3;
table[3][3] = 4;
table[3][4] = 5;
table[4][0] = 1;
table[4][1] = 2;
table[4][2] = 3;
table[4][3] = 4;
table[4][4] = 5;
/* System.out.print table */