Write the code for the following output:
1 2 3 4
5 6 7
8 9
10
As we can observe in the output, for every line, one number is decrementing. We will look at the concept of the outer loop and inner loop here. The code will be as follows:
int k=1;
for(int i=0;i<4;i++)
// (outer for loop) it will loop for 4 times
{
//System.out.println("outer loop started");
for(int j=1;j<=4;j++) //(inner for loop)
{
System.out.print("k");
System.out.print(" ");
}
System.out.println(" ");
}