September 2018
Beginner
156 pages
3h 31m
English
Write the code for the following output:
1 2 3 45 6 78 910
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("\t"); } System.out.println(" "); }
Read now
Unlock full access