Computer Applications

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);

Java

Java Nested for Loops

2 Likes

Answer

20

Working

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.

Answered By

2 Likes


Related Questions