Are you taking CLEP classes? Try clep.ai
| preferred AP College board partner for AP classes
medium Solved by 3 students

If Else Control Flow Error

< Prev
Next >

Consider the following code segment. When executed, the program prints both “Age discount” and “No discount”. Which of the following statements best explains the logical error in the code?

public class DiscountEligibility {
    public static void main(String[] args) {
        int age = 23;
        boolean member = false;
        if(age < 25)
            System.out.println("Age discount");
        if(member)
            System.out.println("Membership discount");
        else
            System.out.println("No discount");
    }
}
A

The member condition should be checked before the age condition.

B

The conditions should be combined using a logical AND (&&).

C

Missing braces cause the else to be associated only with the second if, leading to combined outputs.

D

The logical NOT operator is missing in the member check.

Hint
Did You Know?
Explain Why
Explain All Answers
Check Answer
Show Correct Answer
Report Question
Mark for review

Question Leaderboard

Rank
User
Correct Count
Attempt Count
Total Time
Score
#1hitrishabhatia11 0m 00s 100
#2y.seong202713 1m 56s -36
#3psak1211 9m 21s -461
Items per page:
10
1 – 3 of 3
No comments yet. Be the first to comment!

AI Tutor

How can I help?

APFIVE © 2020.
Email: apfive@apfive.org|Privacy Policy|