0
0
Javaprogramming~10 mins

Else–if ladder 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 number is positive.

Java
int num = 10;
if (num [1] 0) {
    System.out.println("Positive number");
}
Drag options to blanks, or click blank then click option'
A==
B>
C<
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' will check for negative numbers.
Using '==' checks only if the number is zero.
2fill in blank
medium

Complete the else-if ladder to check if a number is zero.

Java
int num = 0;
if (num > 0) {
    System.out.println("Positive number");
} else if (num [1] 0) {
    System.out.println("Zero");
} else {
    System.out.println("Negative number");
}
Drag options to blanks, or click blank then click option'
A==
B<
C>=
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' or '>=' will not correctly check for zero.
Using '!=' checks for not equal, which is incorrect here.
3fill in blank
hard

Fix the error in the else-if ladder condition to check if a number is negative.

Java
int num = -5;
if (num > 0) {
    System.out.println("Positive number");
} else if (num [1] 0) {
    System.out.println("Negative number");
} else {
    System.out.println("Zero");
}
Drag options to blanks, or click blank then click option'
A<
B>
C==
D>=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' checks for positive numbers, not negative.
Using '==' checks for equality, not negativity.
4fill in blank
hard

Fill both blanks to complete the else-if ladder that prints the size category based on age.

Java
int age = 20;
if (age [1] 12) {
    System.out.println("Child");
} else if (age [2] 19) {
    System.out.println("Teenager");
} else {
    System.out.println("Adult");
}
Drag options to blanks, or click blank then click option'
A<=
B>=
C<
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' instead of range checks.
Mixing up '<' and '>=' operators.
5fill in blank
hard

Fill all three blanks to complete the else-if ladder that categorizes temperature.

Java
int temp = 30;
if (temp [1] 0) {
    System.out.println("Freezing");
} else if (temp [2] 30) {
    System.out.println("Cold");
} else if (temp [3] 60) {
    System.out.println("Warm");
} else {
    System.out.println("Hot");
}
Drag options to blanks, or click blank then click option'
A<=
B<
C>
D>=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' instead of '<=' for freezing condition.
Confusing '>=' and '<' in conditions.