Skip to content
Sharp

Core Java · interview question

Why does using int division to calculate the average price of items in a cart change runtime behavior?

Multiple choiceHardchapter-1-curatedpremiumcore-javanumeric-types-and-money-basics
Choose one answer
Answer and explanation

Correct answer

B. It truncates the decimal part.

Why

Int division in Java truncates the decimal part, returning only the integer quotient. This can lead to loss of precision in the average calculation.

Test yourself on Core Java

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

Start free test
All Core Java questions →