This week's giveaway is in the Spring forum.We're giving away four copies of Learn Spring Security (video course) and have Eugen Paraschiv on-line!See this thread for details.
Win a copy of Learn Spring Security (video course) this week in the Spring forum!

Settle dispute - Java Fundamentals

nick angel
Ranch Hand
Posts: 39
Good day to all.
I have a question concerning language fundamentals. Our teacher's assistant gave a number of exercises
but on this one question I have a differing view with my T.A.

The question is as follows:

I found that it would yield a float of value of 1.0.
My T.A. tells me that it is a double of value 1.0.

If I am wrong could anyone please explain, as I was not given an explanation why my T.A.
was convinced of my error.

Thank you very much in advance.

Jelle Klap
Bartender
Posts: 1951
7
What happens in the code above is the following:
- chars are cast to int values, yielding int value 69 and int value 68 respectively.
- int value 68 is subtracted from int value 69 yielding int value 1.
- int value 1 is cast to a float, yielding float value 1.0f.
- float value 1.0f is then multiplied by double value 1.0d yielding double value 1.0d

Henrique Ordine
Ranch Hand
Posts: 129
I found this about operator precedence.

nick angel
Ranch Hand
Posts: 39
Thank you so much for your replies.
If only my T.A.s were as thoughtful.

marc weber
Sheriff
Posts: 11343
Jelle already explained this, but I can't resist drawing a picture...

Ilja Preuss
author
Sheriff
Posts: 14112
Originally posted by marc weber:
Jelle already explained this, but I can't resist drawing a picture...

Nice!