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

15th Dec 2016, 1:05 AM
Atanas Ivanov
Atanas Ivanov - avatar
4 Answers
+ 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)
15th Dec 2016, 1:27 AM
Maksym ZieliƄski
Maksym ZieliƄski - avatar
+ 1
the short answer is because b (which = 12) is in fact greater than 3. so the system prints out a(which is 11).
15th Dec 2016, 1:20 AM
Tarique Shams
Tarique Shams - avatar
0
a > 100 = false ; or ..... b > 3 = true ; a fffff b ttttt System.out.println(a); :)
15th Dec 2016, 2:36 AM
Ahmed Koudier
Ahmed Koudier - avatar
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).
15th Dec 2016, 2:37 AM
lowshuen