Skip to content
Sharp

Core Java · interview question

How many times will the loop execute if the 'cart' array contains three items?

Multiple choiceEasychapter-1-curatedpremiumcore-javaloops-and-iteration
java
int[] cart = {15, 25, 35}; for (int i = 0; i < cart.length; i++) { System.out.println(cart[i]); }
Choose one answer
Answer and explanation

Correct answer

D. 3

Why

The loop executes once for each element in the array, so it will run three times.

Test yourself on Core Java

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

Start free test
All Core Java questions →