Skip to content
Sharp

Core Java · interview question

Given the following loop if no prices are over $100, what outcome should you expect?

Multiple choiceHardchapter-1-curatedpremiumcore-javaloops-and-iteration
java
int[] prices = {20, 50, 80}; int total = 0; for (int price : prices) { if (price > 100) total += price; } System.out.println("Total: " + total);
Choose one answer
Answer and explanation

Correct answer

D. Total: 0

Why

Since the if condition only adds prices over $100, and none meet this condition, the total remains 0.

Test yourself on Core Java

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

Start free test
All Core Java questions →