+ 17
Can someone please explain how 6 is the output?
public class Program { public static void main(String[] args) { int a = 0; do { a+=2; } while (a<5); System.out.println(a); } }
4 Respuestas
+ 5
The loop is done 3 times
+ 13
First loop,
a = 0
Then increased by 2
a = 2
Checking for condition: a < 5 => 2 < 5 ✅
Second loop,
a = 2
Incrementing by 2
a = 4
Checking for condition: a < 5 => 4 < 5 ✅
Third loop,
a = 4
Incrementing by 2
a = 6
Checking for condition: a < 5 => 6 < 5 ❌
Loop breaks
Final value of a = 6 🙌
+ 9
Thank you
+ 2
thank you