Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to increment the variable count by 1 using a unary operator.
Java
int count = 5; count[1];
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '--' which decreases the value.
Using '+=' which is not a unary operator.
Using '-' which subtracts but is not unary increment.
✗ Incorrect
The unary increment operator
++ increases the value of count by 1.2fill in blank
mediumComplete the code to negate the boolean variable isActive using a unary operator.
Java
boolean isActive = true;
isActive = [1]isActive; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '++' or '--' which are for numeric increments or decrements.
Using '~' which is bitwise complement, not for booleans.
✗ Incorrect
The unary logical complement operator
! negates a boolean value.3fill in blank
hardFix the error in the code by choosing the correct unary operator to decrement num by 1.
Java
int num = 10; num[1];
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '++' which increases the value.
Using '+' or '*' which are binary operators and cause errors here.
✗ Incorrect
The unary decrement operator
-- decreases the value of num by 1.4fill in blank
hardFill both blanks to create a map of numbers to their negations using unary operators.
Java
Map<Integer, Integer> negations = Map.of(1, [1]1, 2, [2]2);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '++' or '--' which change the number by one, not negate.
Using '!' which is for booleans, not numbers.
✗ Incorrect
The unary minus operator
- negates numbers, turning positive to negative.5fill in blank
hardFill all three blanks to create a map where keys are numbers and values are their incremented, negated, and decremented forms respectively.
Java
int one = 1, two = 2, three = 3; Map<Integer, Integer> results = Map.of( one, [1]one, two, [2]two, three, [3]three);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!' which is only for booleans.
Mixing prefix and postfix operators incorrectly.
✗ Incorrect
Use
++ to increment, - to negate, and -- to decrement the numbers.