0
0
Javaprogramming~10 mins

Why conditional statements 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 print "Adult" if age is 18 or more.

Java
int age = 20;
if (age [1] 18) {
    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 '>=' causes the condition to be false for age 20.
Using '==' only checks if age is exactly 18, not more.
2fill in blank
medium

Complete the code to print "Even" if number is divisible by 2.

Java
int number = 10;
if (number [1] 2 == 0) {
    System.out.println("Even");
}
Drag options to blanks, or click blank then click option'
A+
B/
C%
D*
Attempts:
3 left
💡 Hint
Common Mistakes
Using '/' divides the number but does not check remainder.
Using '*' or '+' does not help check divisibility.
3fill in blank
hard

Fix the error in the condition to check if score is less than 50.

Java
int score = 45;
if (score [1] 50) {
    System.out.println("Fail");
}
Drag options to blanks, or click blank then click option'
A<
B>
C==
D>=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' checks if score is greater than 50, which is wrong here.
Using '==' checks equality, not less than.
4fill in blank
hard

Fill both blanks to print "Teenager" if age is between 13 and 19 inclusive.

Java
int age = 15;
if (age [1] 13 && age [2] 19) {
    System.out.println("Teenager");
}
Drag options to blanks, or click blank then click option'
A>=
B<
C<=
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '<=' excludes age 19.
Using '>' instead of '>=' excludes age 13.
5fill in blank
hard

Fill all three blanks to print "Eligible" if salary is above 3000, age is at least 18, and experience is more than 2 years.

Java
int salary = 3500;
int age = 25;
int experience = 3;
if (salary [1] 3000 && age [2] 18 && experience [3] 2) {
    System.out.println("Eligible");
}
Drag options to blanks, or click blank then click option'
A>=
B>
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>=' for salary includes 3000, but requirement is above 3000.
Using '<' for experience is incorrect here.