ICSE Class 10 Computer Applications Question 55 of 76

Revising Basic Java Concepts — Question 59

Back to all questions
59
Question

Question 36

Give the output of the following program segment and also mention how many times the loop is executed.

int i;
for (i = 5 ; i > 10; i++) 
    System.out.println(i);
System.out.println(i * 4);
Answer
Output
20
Explanation

Initially i = 5.

The test condition i > 10 is false and so the control comes to the next statement following 'for' loop — System.out.println(i * 4); and prints 20 (5 * 4) on the screen.