Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Settle dispute - Java Fundamentals

 
nick angel
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Henrique Ordine
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found this about operator precedence.
 
nick angel
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jelle already explained this, but I can't resist drawing a picture...
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by marc weber:
Jelle already explained this, but I can't resist drawing a picture...


Nice!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic