Sail E0 Webinar
Question


What will be the output of the program?


int x = l, y = 6;
while (y--)
{
x++;
}
System.out.println("x = " + x +" y = " + y);
Options:
A .  x = 6 y = 0
B .  x = 7 y = 0
C .  x = 6 y = -1
D .  Compilation fails.
Answer: Option D

Compilation fails because the while loop demands a boolean argument for it's looping

 condition, but in the code, it's given an int argument.

while(true) { //insert code here }



Was this answer helpful ?
Next Question

Submit Solution

Your email address will not be published. Required fields are marked *

Latest Videos

Latest Test Papers