Q: What is the output of the Java code snippet? int a=25, b=30; boolean c = a>25 | b<40; if(c) { System.out.println("RABBIT"); } else { System.out.println("GOOSE"); }
Solution: false | true is true only.
Q: What is the output of the Java code snippet? int a=25, b=30; boolean c = a>25 & b<40; if(c) { System.out.println("RABBIT"); } else { System.out.println("GOOSE"); }
Solution: false & true is false only.
Q: What is the output of the Java code snippet? int a=3, b=8; boolean c = a>5 && ++b>6; System.out.println(b);
Solution: ++b>6 is not evaluated as the first operand itself is false. Short Circuit AND operator skips the second expression.
Q: What is the output of the Java code snippet? int a=5, b=9; boolean c = a>1 || b++<10; System.out.println(b);
Solution: b++<10 is not evaluated by the Short Circuit OR operator as the first operand is already true. There is no need to check the second expression.
Q: What is the output of the Java code snippet? int a=4, b=6, c=8; boolean d = a>5 && b>5 & c++<10; System.out.println(c);
Solution: Grouping or association of operands is done first based on the priority. a>5 && (b>5 & c++<10) false && (anything) false
Q: What is the output of the Java code snippet? int a=4, b=8; boolean c = a>1 ^ b<10; if(c) { System.out.println("TREE"); } else { System.out.println("BIRD"); }
Solution: The exclusive operator (^) gives an output of TRUE only if both the operands are different.
Q: What is the output of the Java code snippet? int a=5; boolean b = a>1 || false; b ^= false; System.out.println(b);
Solution: b ^= false; b = b^false; b = true ^ false; b = true;
Q: What is the output of the Java code snippet? int a=4, b=8; boolean c = a>2 ^ b<10 & false; System.out.println(c);
Solution: AND has a higher priority than Exclusive OR. a>2 ^ b<10 & false a>2 ^ (b<10 & false) a>2 ^ (true & false) a>2 ^ (false) true ^ false true
Q: What is the output of the Java code snippet? int a=3, b=1; int c = a & b; System.out.println("CAT " + c);
Solution: Here AND & operator is used with numbers. So, it is a Bitwise operator, not a Logical operator.
Q: If an AND (&) operator is applied with two integers, what is this operator?
Solution: no solution
You Have Score    | /10 |