Operators and Expression Operators and Expression Arithmetic Operators, Relational and Logical Operators, Bitwise Operators, Increment and Decrement Operators, Conditional (Ternary) Operator, Compound Expressions 1 / 10 What is the output of the following code? int a = 10, b = 3; System.out.println(a / b); 3.33 3 4 Compilation Error 2 / 10 What will this expression evaluate to? int result = 10 + 20 * 3 / 2 – 5; System.out.println(result); 25 30 35 40 According to operator precedence: 20 * 3 = 60, 60 / 2 = 30, 10 + 30 = 40, 40 - 5 = 35. According to operator precedence: 20 * 3 = 60, 60 / 2 = 30, 10 + 30 = 40, 40 - 5 = 35. 3 / 10 What will the following code output? int a = 5, b = 10; System.out.println(a > 3 && b < 15); true false Compilation Error Runtime Error Both conditions a > 3 and b < 15 are true, so the && operator returns true. Both conditions a > 3 and b < 15 are true, so the && operator returns true. 4 / 10 What is the output of this code? int x = 10; System.out.println(x > 5 || x++ < 20); System.out.println(x); true, 11 true, 10 false, 11 false, 10 The || operator short-circuits after x > 5 evaluates to true. The second condition is not evaluated, and x remains unchanged The || operator short-circuits after x > 5 evaluates to true. The second condition is not evaluated, and x remains unchanged 5 / 10 What will the following code output? int a = 5, b = 3; System.out.println(a & b); 7 1 3 5 The bitwise AND operation between 5 (0101) and 3 (0011) results in 0001, which is 1 The bitwise AND operation between 5 (0101) and 3 (0011) results in 0001, which is 1 6 / 10 What is the result of the expression 8 >> 2? 2 4 8 16 The right shift operator >> shifts the bits of 8 (1000) two places to the right, resulting in 0010 or 2 The right shift operator >> shifts the bits of 8 (1000) two places to the right, resulting in 0010 or 2 7 / 10 What will the following code print? int x = 10; System.out.println(x++ + ++x); 22 21 20 Compilation Error x++ uses the value of 10 and then increments x to 11. ++x increments x to 12 and uses it. Result = 10 + 12 = 22. x++ uses the value of 10 and then increments x to 11. ++x increments x to 12 and uses it. Result = 10 + 12 = 22. 8 / 10 What will be the value of x after the following code is executed? int x = 5; x += x++ + ++x; 15 16 17 18 9 / 10 What is the output of the following code? int a = 10, b = 20; int result = (a > b) ? a : b; System.out.println(result); 10 20 true Compilation Error Since a > b is false, the ternary operator returns b Since a > b is false, the ternary operator returns b 10 / 10 What will the following code print? int a = 5; int b = 10; int c = 15; int result = a * b + c / b – a; System.out.println(result); 50 51 48 49 Operator precedence applies: a * b = 50, c / b = 1, 50 + 1 - 5 = 49. Operator precedence applies: a * b = 50, c / b = 1, 50 + 1 - 5 = 49. Your score is By WordPress Quiz plugin