0
What is the output of the following code? Can somebody explain why the answer is 11 tnx
int a = 11; int b = 12; int c = 40; if (a > 100 || b > 3) { System.out.println(a); } else { System.out.println(c); }
4 ответов
+ 2
When you use "or" operator, code will execute if:
1. One of conditions is true.
2. Both of conditions are true.
(0||1) is like (1)
+ 1
the short answer is because b (which = 12) is in fact greater than 3. so the system prints out a(which is 11).
0
a > 100 = false ;
or .....
b > 3 = true ;
a fffff
b ttttt
System.out.println(a);
:)
0
false or true = true
true or true = true
false or false = false
true and true = true
true and false = false
false and false = false
-------------------------------------------------------
if(a > 100 || b > 3):
a > 100 is false
b > 3 is true
true or false evaluates true
hence, it prints out a which is 11
Since, the if condition is met, hence, it does not enter the else statement which is why it prints out only a (11).