Identify the logic error in the code below. The code is supposed to display a single message “child”, “adult” or “senior” for any value of age:
if (age < 18) {
System.out.println("child");
} else if (age >= 18) {
System.out.println("adult");
} else if (age > 65) {
System.out.println("senior");
}
Question 1 options:
If we take a look at the first else if block, the code runs whenever the age is greater than or equal to 18. This means that senior will never be displayed. Answer choice D is correct.