Skip to content
Sharp

Core Java · interview question

How can you ensure a loop calculates the total of item prices only if they are above $50?

Multiple choiceMediumchapter-1-curatedpremiumcore-javaloops-and-iteration
Choose one answer
Answer and explanation

Correct answer

B. Add an if statement inside the loop to check the price.

Why

Using an if statement inside the loop allows you to check each price before adding it to the total, ensuring only prices above $50 are included.

Test yourself on Core Java

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

Start free test
All Core Java questions →