Skip to content
Sharp

Core Java · interview question

What type of loop would be best to calculate the total price of items in a shopping cart when you know the number of items beforehand?

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

Correct answer

D. For loop

Why

A 'for loop' is ideal when the number of iterations is known before the loop starts. It provides a concise way to iterate through a collection or perform a set number of operations.

Test yourself on Core Java

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

Start free test
All Core Java questions →