How is the output 33 and not 34. Can someone help me understand this? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How is the output 33 and not 34. Can someone help me understand this?

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); } }

13th Dec 2019, 4:11 AM
Abhi
Abhi - avatar
3 Answers
0
2 > 3 false 2++ rest of if() expresion is ignored, because result is still false // (false && true = false )
13th Dec 2019, 4:42 AM
zemiak
0
The reason is: if(false &&... => the rest is not checking during runtime, because from Java's point of view it makes no sense (the result will be false anyway).
13th Dec 2019, 4:45 AM
Marnyansky
Marnyansky - avatar
0
Thank you very much guys for the clarification. Helped a lot.!!
13th Dec 2019, 4:47 AM
Abhi
Abhi - avatar