Question on a JAVA challenge regarding increment and if-statement | SoloLearn: Learn to code for FREE!

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

1/16/2020 12:30:09 AM

Elise Ray

2 Answers

New Answer

+3

&& returns only true when both conditions are true. a++ > b returns false -> the rest is ignored a + b -> integer a + " " + b -> string

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