0
0
Javaprogramming~10 mins

Relational 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 check if a is greater than b.

Java
boolean result = a [1] b;
Drag options to blanks, or click blank then click option'
A<
B!=
C>
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' instead of '>' to compare values.
Using '<' which means less than.
2fill in blank
medium

Complete the code to check if x is less than or equal to y.

Java
boolean check = x [1] y;
Drag options to blanks, or click blank then click option'
A>=
B!=
C==
D<=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>=' which means greater than or equal to.
Using '==' which means equal to.
3fill in blank
hard

Fix the error in the code to check if num1 is not equal to num2.

Java
if (num1 [1] num2) {
    System.out.println("Not equal");
}
Drag options to blanks, or click blank then click option'
A!=
B==
C>
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' which checks for equality, not inequality.
Using '>' or '<' which check order, not equality.
4fill in blank
hard

Fill both blanks to create a condition that checks if value is between 10 and 20 inclusive.

Java
if (value [1] 10 && value [2] 20) {
    System.out.println("Within range");
}
Drag options to blanks, or click blank then click option'
A>=
B<
C<=
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '<=' for the upper bound.
Using '>' instead of '>=' for the lower bound.
5fill in blank
hard

Fill all three blanks to create a map that stores keys as uppercase strings and values greater than zero.

Java
Map<String, Integer> filtered = data.entrySet().stream()
    .filter(e -> e.getValue() [1] 0)
    .collect(Collectors.toMap(
        e -> e.getKey().[2](),
        e -> e.getValue() [3] 0
    ));
Drag options to blanks, or click blank then click option'
A>
BtoUpperCase
C+
D>=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>=' instead of '>' in filter changes condition.
Using 'toLowerCase' instead of 'toUpperCase'.
Using '-' instead of '+' for values.