Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-' instead of '+' will subtract the numbers.
Using '*' or '/' will multiply or divide, not add.
✗ Incorrect
The + operator adds two numbers together.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '+' will add instead of multiply.
Using '/' will divide instead of multiply.
✗ Incorrect
The * operator multiplies two numbers.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-' will subtract instead of divide.
Using '*' will multiply instead of divide.
✗ Incorrect
The / operator divides the numerator by the denominator.
4fill in blank
hardFill 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'
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.
✗ Incorrect
The % operator gives the remainder of division. The + operator adds 2 to the remainder.
5fill in blank
hardFill 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'
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.
✗ Incorrect
The operator > checks if the number is greater than 3. The * operator squares the number. The .toString() method converts the map to a string for printing.