KnowledgeBoat Logo

Output Questions for Class 10 ICSE Computer Applications

Give the output of the following program segment and also mention the number of times the loop is executed:

int x, y;
for (x = 9, y = 4; x <= 45; x+=9) {
    if (x % y == 0)
        break;
}
System.out.println(x);

Java

Java Iterative Stmts

ICSE

14 Likes

Answer

36

Loop executes 4 times

Working

Below table shows the dry run of the loop:

xyRemarks
941st Iteration
1842nd Iteration
2743rd Iteration
3644th Iteration. As 36 % 4 is 0 so break statement terminates the loop.

Answered By

10 Likes