Given the code fragment:
What is the result?
Given the code fragment:
What is the result?
First, evaluate each line due to operators and increments. The first println(a++ > 10 || ++b <= 21) changes 'a' from 10 to 11 after comparison and 'b' from 20 to 21 before comparison. It evaluates to (10 > 10 || 21 <= 21), which is false || true, resulting in true. The second println(a > 10 && ++b <= 22) changes 'b' from 21 to 22 before comparison. It evaluates to (11 > 10 && 22 <= 22), which is true && true, resulting in true. The third println(a <= 11 && b == 22) evaluates to (11 <= 11 && 22 == 22), both conditions are true, resulting in true. The last println(c++ == 31 && a++ == 11 || b++ == 22) changes 'c' from 30 to 31 after comparison, 'a' from 11 to 12 after comparison, and 'b' from 22 to 23. It evaluates to (30 == 31 && 11 == 11 || 22 == 22), false && true || true, which is false || true, resulting in true. Therefore, the correct option is true, true, true, false.
guys take care the output will be TRUE four times so the answer is C if you check it on the compiler you will get the same output i mention , because the || operator requires only one to be true.
C is the correct answer because the second part of D has post-increments so it's will stay 22 , the step after D B=23
Corret Answer should be D
Corret Answer should be D
answer is D
All are true is the result that I got when compiled.
T T T T System.out.println(a++ > 10 || ++b <= 21); System.out.println(" " + a + " " + b); System.out.println(a > 10 && ++b <= 22); System.out.println(" " + a + " " + b); System.out.println(a <= 11 && b == 22); System.out.println(" " + a + " " + b); System.out.println(c++ == 31 && a++ == 11 || b++ == 22); System.out.println(" " + a); System.out.println(" " + a + " " + b + " " + c); The expression becomes true || true, which is true. Value of a after this line: 12 Value of b after this line: 23 Value of c after this line: 31
I tried to insert on the compiler and the result is : true true false true.
The answer is D, because both prefix (++a) and postfix (a++) operators kept its result. E.g: After the first println System.out.println(a++ > 10 || ++b <= 21); The value of a is 11, therefore by the time it reaches the fourth println, a++ would already be 12, not 11.
the answer is C
Correct answer is D
The correct answer should be A. operand AND can only be true if both expression correct. OR can only be true if either one is correct.