0
0
Javaprogramming~10 mins

Arithmetic 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 two numbers and print the result.

Java
int a = 5;
int b = 3;
int sum = a [1] b;
System.out.println(sum);
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 the numbers.
Using '*' or '/' will multiply or divide, not add.
2fill in blank
medium

Complete the code to multiply two numbers and print the result.

Java
int x = 4;
int y = 7;
int product = x [1] y;
System.out.println(product);
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 '/' will divide instead of multiply.
3fill in blank
hard

Fix the error in the code to correctly divide two numbers and print the result.

Java
int numerator = 10;
int denominator = 2;
int result = numerator [1] denominator;
System.out.println(result);
Drag options to blanks, or click blank then click option'
A/
B-
C+
D*
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-' will subtract instead of divide.
Using '*' will multiply instead of divide.
4fill in blank
hard

Fill both blanks to calculate the remainder of division and print it.

Java
int dividend = 17;
int divisor = 5;
int remainder = dividend [1] divisor;
System.out.println(remainder [2] 2);
Drag options to blanks, or click blank then click option'
A%
B+
C-
D*
Attempts:
3 left
💡 Hint
Common Mistakes
Using '/' instead of '%' will give the quotient, not remainder.
Using '-' or '*' in the second blank will not add 2.
5fill in blank
hard

Fill all three blanks to create a map of numbers to their squares for numbers greater than 3.

Java
Map<Integer, Integer> squares = new HashMap<>();
for (int num = 1; num <= 5; num++) {
    if (num [1] 3) {
        squares.put(num, num [2] num);
    }
}
System.out.println(squares[3]);
Drag options to blanks, or click blank then click option'
A>
B*
C.toString()
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' will filter wrong numbers.
Using '+' instead of '*' will not square the number.
Printing the map without converting to string may not show expected output.