why && 11 and || 12 | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4

why && 11 and || 12

int a = 10; /* if((a++ > 15) || (10 > a++)){ System.out.println(true); System.out.println(a); // 12 }else{ System.out.println(false); System.out.println(a); } */ if((a++ > 15) && (10 > a++)){ System.out.println(true); System.out.println(a); // 11 }else{ System.out.println(false); System.out.println(a); }

15th Jun 2018, 11:57 AM
youk
4 Answers
+ 2
The first part of the if is checked first so if its an or and the first is true it will not bother running the rest of the checks.... An and works the other way around if the first check is false then the second part of the check is ignored.
15th Jun 2018, 3:34 PM
Nommer101
Nommer101 - avatar
+ 2
the first one is true if a++ is greater than 15 OR 10 is greater than a++ the second one is true if a++ is greater than 15 AND 10 is greater than a++
15th Jun 2018, 12:12 PM
Roel
Roel - avatar
+ 1
a is 12 because: a=10; if (a>15){//10 a++; print true; print a;//11 }else { a++; if (10>a){//11 a++; print true; print a;//12 }else { a++ print false; print a; } }
15th Jun 2018, 3:26 PM
Nommer101
Nommer101 - avatar
+ 1
a is 11 because: a=10; if (a>15){ a++; if (a>10){ a++; print true; print a;//12 }else { a++; print false; print a;//12 } }else { a++; print false; print a;//11 }
15th Jun 2018, 3:30 PM
Nommer101
Nommer101 - avatar