Mixed Integer and Float

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
go to previous page   go to home page   hear noise   go to next page

Answer:

199/50 = 3 

50 goes into 199 three times and the remainder, 49, is dropped.

Mixed Integer and Float

Integer division is easy enough to see when it is by itself, but here is a more confusing case of the same thing:

1.5 + 7/2

The division is done first, because / has higher precedence than +. The result, 3, is an integer. Now the floating point 1.5 is added to integer 3 to get floating point 4.5.

Integer arithmetic might be used in some parts of an expression and not in others, even though the final value of the expression is floating point.

QUESTION 7:

What is the result of evaluating the following expression:

1/2 + 1/2