Flow Control

Q1: What will be the output of the program?
for (int i = 0; i < 4; i += 2) 
{ 
    System.out.print(i + ' '); 
} 
System.out.println(i); /* Line 5 */

A 0 2 4 5

B Compilation fails.

C 0 2 4

D 0 1 2 3 4

ANS:A - 0 2 4

Compilation fails on the line 5 - System.out.println(i); as the variable i has only been declared within the for loop. It is not a recognised variable outside the code block of loop.



img not found
img

For help Students Orientation
Mcqs Questions

One stop destination for examination, preparation, recruitment, and more. Specially designed online test to solve all your preparation worries. Go wherever you want to and practice whenever you want, using the online test platform.