Arizona State University (ASU) CSE110 Principles of Programming Exam 1 Practice

Session length

1 / 20

What will be the output of the expression 15 / 4 in Java?

3.75

4

3

In Java, when you divide two integers, the result is also an integer. This means that any fractional part of the division is truncated, rather than rounded. In the expression 15 / 4, both 15 and 4 are integers. The division operation here results in 3, as 4 goes into 15 three times with a remainder, but since the operation is performed with integer division, the remainder is discarded. This behavior is a key characteristic of integer arithmetic in Java, which is different from floating-point arithmetic that would yield 3.75 if either operand were a floating-point number. Thus, the output of the expression 15 / 4 will be 3.

Get further explanation with Examzify DeepDiveBeta

15

Next Question
Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy