Challenge - 5 Problems
Assignment Operator Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of compound assignment with multiplication
What is the output of this Java code snippet?
Java
int a = 5; a *= 3 + 2; System.out.println(a);
Attempts:
2 left
💡 Hint
Remember that compound assignments evaluate the right side first, then multiply.
✗ Incorrect
The expression a *= 3 + 2 is equivalent to a = a * (3 + 2). So, a = 5 * 5 = 25.
❓ Predict Output
intermediate2:00remaining
Result of bitwise OR assignment
What will be printed after running this Java code?
Java
int x = 6; // binary 0110 x |= 3; // binary 0011 System.out.println(x);
Attempts:
2 left
💡 Hint
Bitwise OR sets bits where either operand has a 1.
✗ Incorrect
6 in binary is 0110, 3 is 0011. OR operation gives 0111 which is 7 in decimal.
❓ Predict Output
advanced2:00remaining
Output of chained assignment with increment
What is the output of this Java code snippet?
Java
int a = 2; int b = 3; int c = a += b++; System.out.println(a + "," + b + "," + c);
Attempts:
2 left
💡 Hint
Remember that b++ uses b's value before incrementing.
✗ Incorrect
b++ uses b's current value (3) then increments b to 4. So a += 3 means a = 2 + 3 = 5. c is assigned this new a value (5). b is now 4.
❓ Predict Output
advanced2:00remaining
Effect of right shift assignment operator
What will be printed after executing this Java code?
Java
int num = 32; num >>= 3; System.out.println(num);
Attempts:
2 left
💡 Hint
Right shift divides the number by 2 for each shift.
✗ Incorrect
Right shifting 32 by 3 bits divides it by 2^3 = 8, so 32 / 8 = 4.
❓ Predict Output
expert3:00remaining
Value of variable after complex assignment
What is the value of variable
result after running this Java code?Java
int x = 10; int y = 5; int result = 0; result += x > y ? x -= 3 : y += 3; System.out.println(result);
Attempts:
2 left
💡 Hint
The ternary operator chooses which assignment to perform based on the condition.
✗ Incorrect
Since x (10) > y (5), the true branch executes: x -= 3, so x becomes 7. Then result += 7, so result is 7.