Welcome Guest | Sign in | Register
Flow Control - Discussion Page For Q.2758 | Java Programming Questions and Answers | Java Programming Free Online-Tests | LucentBlackBoard | LucentBlackBoard.com

Home > Java Programming > Flow Control > Questions and Answers

Q: What will be the output of the program?

int i = O;
while(1)
{
if(i == 4)
{
break;
}
++i;
}
System.out.println("i = " + i);
A. i = 0 B. i = 3
C. i = 4 D. Compilation fails.

Answer and Explanation

Answer:Compilation fails.

Explanation:
Compilation fails because the argument of the while loop, the condition, must be of primitive type boolean. In Java, 1 does not represent the true state of a boolean, rather it is seen as an integer.

Comment on this Question

Name:

Loading...




Partner Sites
LucentBlackBoard.com                  SoftLucent.com                  LucentJobs.com
All rights reserved © 2012-2015 SoftLucent.