0
0
Javaprogramming~10 mins

Assignment operators in Java - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to add 5 to the variable num using an assignment operator.

Java
int num = 10;
num [1] 5;
Drag options to blanks, or click blank then click option'
A+=
B-=
C*=
D/=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-' instead of '+' will subtract instead of add.
Using '*' or '/' will multiply or divide, not add.
2fill in blank
medium

Complete the code to multiply value by 3 using an assignment operator.

Java
int value = 4;
value [1] 3;
Drag options to blanks, or click blank then click option'
A*=
B+=
C-=
D/=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '+=' will add instead of multiply.
Using '-=' or '/=' will subtract or divide, not multiply.
3fill in blank
hard

Fix the error in the code by choosing the correct assignment operator to subtract 2 from count.

Java
int count = 7;
count [1] 2;
Drag options to blanks, or click blank then click option'
A*=
B-=
C+=
D/=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '+=' will increase instead of decrease.
Using '*=' or '/=' will multiply or divide, not subtract.
4fill in blank
hard

Fill both blanks to divide total by 4 and assign the result back, then add 10 to total.

Java
int total = 40;
total [1] 4;
total [2] 10;
Drag options to blanks, or click blank then click option'
A/=
B+=
C-=
D*=
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up '+' and '-' operators.
Using '*=' instead of '/=' for division.
5fill in blank
hard

Fill all three blanks to multiply score by 2, subtract 5, then add 3.

Java
int score = 10;
score [1] 2;
score [2] 5;
score [3] 3;
Drag options to blanks, or click blank then click option'
A*=
B-=
C+=
D/=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '+=' instead of '*=' for multiplication.
Mixing the order of operations.