+ 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); }
4 ответов
+ 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.
+ 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++
+ 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;
}
}
+ 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
}