what is the output of the following code below ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

what is the output of the following code below ?

int a = 11; int b = 12; int c = 40; if (a > 100 || b > 3) { System.out.println(a); } else { System.out.println(c); } i dont understand about the code above...plz help me

22nd Jun 2019, 2:03 PM
Boy Arya
Boy Arya - avatar
3 Answers
+ 12
Hello !! The variables a is initialized to 11 and b to 12. In if condition, a>100 || b>3 evaluates to be true as a>100 is false as 11 is not greater than 100 but b>3 is true as 12 is greater than 3. And in between there is a logical OR operator. So any one of two condition would be true and here one condition is treu so the if block evalutes to be true. So the value of a i.e. 11 is printed. Hope this helps !!!
22nd Jun 2019, 2:20 PM
Nova
Nova - avatar
+ 1
The condition is if a>100 OR b>3. b>3 so it prints a. Output is just 11.
22nd Jun 2019, 2:09 PM
Jackson O’Donnell
+ 1
as first condition is false ....but second is true....so for or operator any 1 conditions satisfying results in condition being true....so the value of a is printed
22nd Jun 2019, 5:38 PM
Sachin Motwani
Sachin Motwani - avatar