0
0
Javaprogramming~10 mins

Logical 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 both conditions are true using the AND operator.

Java
boolean result = (a > 5) [1] (b < 10);
Drag options to blanks, or click blank then click option'
A|
B||
C&&
D!
Attempts:
3 left
💡 Hint
Common Mistakes
Using || which means OR instead of AND.
Using single & which is a bitwise operator here.
2fill in blank
medium

Complete the code to check if either condition is true using the OR operator.

Java
boolean result = (x == 0) [1] (y == 1);
Drag options to blanks, or click blank then click option'
A||
B&&
C&
D!
Attempts:
3 left
💡 Hint
Common Mistakes
Using && which means AND instead of OR.
Using single | which is a bitwise operator here.
3fill in blank
hard

Fix the error in the code to negate the condition correctly.

Java
boolean isFalse = [1] flag;
Drag options to blanks, or click blank then click option'
Aflag
B~
C!!
D!
Attempts:
3 left
💡 Hint
Common Mistakes
Using double negation !! which returns the original value.
Using bitwise complement ~ which works on integers, not booleans.
4fill in blank
hard

Fill all three blanks to create a condition that checks if number is between 10 and 20 inclusive.

Java
boolean inRange = (number [1] 10) [2] (number [3] 20);
Drag options to blanks, or click blank then click option'
A>=
B&&
C<=
D||
Attempts:
3 left
💡 Hint
Common Mistakes
Using OR instead of AND which allows numbers outside the range.
Using > or < instead of >= or <= which excludes boundary values.
5fill in blank
hard

Fill all three blanks to create a condition that checks if a character is a vowel (a, e, i, o, u).

Java
boolean isVowel = (ch == 'a') [1] (ch == 'e') [2] (ch == 'i') [3] (ch == 'o') || (ch == 'u');
Drag options to blanks, or click blank then click option'
A||
B&&
C==
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using AND instead of OR which requires ch to be all vowels at once.
Using != which checks for not equal.