Example 2

Write the code for the following output:

1
2 3
4 5 6
7 8 9 10

As you can see, the output used in this example is the reverse of the output from first example: 

int k=1;
for(int i=1;i<5;i++)
// (outer for loop) it will loop for 4 times
{
//System.out.println("outer loop started");
for(int j=1;j<=i;j++) //(inner for loop)
{
System.out.print("k");
System.out.print(" ");
k++;
}
System.out.println(" ");
}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.135.190.101