0

Need Help

I don't understand how the results can be 33 when my code is like this? Please explain me public class Program { public static void main(String[] args) { int a = 2, b = 3; if (a++ > b && ++b > 0){ System.out.println(1); }else { System.out.println(a + "" + b); } } }

6th Apr 2021, 4:22 PM
N,8
4 Antworten
+ 1
Try calling a++ outside if() Then replace a++ with a in the if like if(a ...
6th Apr 2021, 4:27 PM
Ananiya Jemberu
Ananiya Jemberu - avatar
+ 1
When the if statement evaluates a, it then increments a. So the next time when to examine a it has become higher.
6th Apr 2021, 4:36 PM
Jerry Hobby
Jerry Hobby - avatar
+ 1
1. if(a++ > b) is false because (2>3). But after this "a" increments in 1 and equal to 3. That's why 33
6th Apr 2021, 4:40 PM
Abdulaziz Mavlonov
Abdulaziz Mavlonov - avatar
0
Thank you all i understand now
6th Apr 2021, 4:48 PM
N,8