What will be the result?
int i = 10;
while(i++ <= 10){
i++;
}
System.out.print(i);
int i = 10;
while(i++ <= 10){
i++;
}
System.out.print(i);A. 10
B. 11
C. 12
D. 13
E. Line 5 will be never reached.
Answer: Option D
Solution (By Examveda Team)
Initially i=10, when it reaches to while statement i++ <= 10 here i = 10 so condition become ture.For next use i become 11 and i++ statment will excuted and i become 12.
Then again its go to while loop and check i++ <=10 here i = 12 so condition becomes fail and i become 13.
Therefore when print statement will execute after while loop it Print 13
Join The Discussion
Comments (2)
Related Questions on Flow Control
What is the purpose of the "if" statement in Java?
A. To execute a block of code conditionally
B. To create loops
C. To declare variables
D. To define methods
A. No output
B. Error
C. Hello
D. 5

can u explain
if we compile the the condition is execute i++=10
then next step i=11 and then i++=11
next step i=12
after two increment while condition executed i++