Skip to content
Sharp

Core Java · interview question

Identify the logical error in the following checkout process code?

Multiple choiceHardchapter-1-curatedpremiumcore-javacode-reading-and-debugging
java
int cartTotal = 60;
if (cartTotal < 50) {
    cartTotal -= 5;
} else {
    cartTotal -= 10;
}
System.out.println(cartTotal);
Choose one answer
Answer and explanation

Correct answer

D. Wrong condition

Why

The condition 'if (cartTotal < 50)' should be 'if (cartTotal >= 50)' to apply the discount when the total is at least 50, not less.

Test yourself on Core Java

A free test with instant, explained results. No account needed.

Start free test
All Core Java questions →