KnowledgeBoat Logo

Output Questions for Class 10 ICSE Computer Applications

Give the output of the following Java program snippet based on nested loops:

int i,j;
first:
for (i=10; i>=5; i--)
{
for (j= 5; j<=i; j++)
{
if (i*j <40)
    continue first; 
System.out.print(j);
}
System.out.println( );
}

Java

Java Nested for Loops

ICSE

16 Likes

Answer

5678910
56789
5678
 
 
 

Working

For the first 3 iterations of outer loop i * j >= 40. After that as the condition of if (i*j <40) becomes true, in each iteration of inner for, continue statement transfers the program control to the next iteration of outer for loop.

Answered By

8 Likes