Need solution | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Need solution

int x=0; int y=2; do{x+=y;} while(x<4); Syste.out.print(++x); How the output is 5? It should 3...

24th Dec 2022, 4:47 AM
Mustakim Rahman
Mustakim Rahman - avatar
1 Answer
+ 3
Initially, the value of x is 0. The do while loop will execute until the condition in while is met. Here the loop will execute twice, i.e., the value of x will become 4. Then, since x = 4 the condition in while is not satisfied as x is not less than 4 and the loop will end. Next you're outputting the value of x after incrementing it by 1. Therefore, the value of x = 4 + 1 = 5.
24th Dec 2022, 6:33 AM
Rivan