+ 1

Question on a JAVA challenge regarding increment and if-statement

Why is 'b' not changed when 'a' did in the codes below? Also, why is there "" between a+b ? int a = 2, b= 3; if(a++ > b && ++b > 0) { System.out.println(1); } else { System.out.println(a + "" + b); }

16th Jan 2020, 12:30 AM
Elise Ray
Elise Ray - avatar
2 odpowiedzi
+ 3
&& returns only true when both conditions are true. a++ > b returns false -> the rest is ignored a + b -> integer a + " " + b -> string
16th Jan 2020, 12:41 AM
Denise Roßberg
Denise Roßberg - avatar
0
But there is a problem....a was treated like integer and b is treated like string....... That cant be posible because a++ raise and ++b didn it
5th Mar 2020, 5:32 PM
Felix Mercado
Felix Mercado - avatar