0
0
Javaprogramming~10 mins

Why operators are needed in Java - Test Your Understanding

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 subtraction or multiplication instead of addition.
2fill in blank
medium

Complete the code to check if a number is greater than 10.

Java
int number = 15;
boolean isGreater = number [1] 10;
System.out.println(isGreater);
Drag options to blanks, or click blank then click option'
A>
B<
C==
D<=
Attempts:
3 left
💡 Hint
Common Mistakes
Using less than or equals instead of greater than.
3fill in blank
hard

Fix the error in the code to multiply two numbers correctly.

Java
int x = 4;
int y = 6;
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 plus or minus instead of multiplication.
4fill in blank
hard

Fill both blanks to create a condition that checks if a number is between 5 and 10 (inclusive).

Java
int num = 7;
boolean isBetween = num [1] 5 && num [2] 10;
System.out.println(isBetween);
Drag options to blanks, or click blank then click option'
A>=
B<
C<=
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using only > or < which excludes the boundary numbers.
5fill in blank
hard

Fill the blanks to create a map of words to their lengths, including only words longer than 3 characters.

Java
Map<String, Integer> lengths = words.stream()
    .filter(word -> word.length() [1] 3)
    .collect(Collectors.toMap(word -> word, word -> word.[2]()));
Drag options to blanks, or click blank then click option'
A>
Blength
Dsubstring
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong comparison operators or wrong methods for length.