This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Settle dispute - Java Fundamentals Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Settle dispute - Java Fundamentals" Watch "Settle dispute - Java Fundamentals" New topic
Author

Settle dispute - Java Fundamentals

nick angel
Ranch Hand

Joined: Dec 14, 2005
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

Joined: Mar 10, 2008
Posts: 1761
    
    7

Your T.A is correct.
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


Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
Henrique Ordine
Ranch Hand

Joined: Sep 03, 2004
Posts: 127
I found this about operator precedence.


J2EE Architect/Developer
nick angel
Ranch Hand

Joined: Dec 14, 2005
Posts: 39
Thank you so much for your replies.
Your explanations and links are greatly appreciated.
If only my T.A.s were as thoughtful.
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Jelle already explained this, but I can't resist drawing a picture...


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by marc weber:
Jelle already explained this, but I can't resist drawing a picture...


Nice!


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Settle dispute - Java Fundamentals