Skip to content
Sharp

Core Java · interview question

In a cart system, how would you use an if-else to apply a discount only if 'isWeekend' is true and 'cartValue' exceeds 150?

Multiple choiceMediumchapter-1-curatedpremiumcore-javaconditions-and-branching
Choose one answer
Answer and explanation

Correct answer

B. If (isWeekend && cartValue > 150) {}

Why

The '&&' operator ensures the discount is applied only when both 'isWeekend' is true and 'cartValue' exceeds 150.

Test yourself on Core Java

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

Start free test
All Core Java questions →