213k views
1 vote
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

User Cbrdy
by
4.6k points

1 Answer

4 votes

Answer:

Following are the java code to this question:

for (int x= 0;x<x1.length;x++)//defining for loop for print column value

{

for (int y= 0;y<x1[x].length;y++)//defining for loop for print row value

{

System.out.print(x1[x][y]=y+1);//print array value

}

System.out.println();// use print method for line spacing

}

Step-by-step explanation:

The full code is defined in the attached file please find it.

In the above-given code, the nested for loop is used, that's function can be defined as follows:

In the outer loop, an x variable is used, that starts from 0 and ends when its value is equal to its array length.

In the inner loop, a y variable is used that also starts from 0 and ends when its value is equal to the length of x, and inside the loop, the print method is used that uses an array to assign value and print in the given order.

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-example-1
User Roy Chan
by
4.8k points