wood burning stoves*
The moose likes Mock Exam Errata and the fly likes Error with JQPlus Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Mock Exam Errata
Bookmark "Error with JQPlus Question" Watch "Error with JQPlus Question" New topic
Author

Error with JQPlus Question

Ken Pullin
Ranch Hand

Joined: Jan 29, 2001
Posts: 43
I was working on this question and this was the answer. When I ran it on my machine, I came up with "True".
The following code will print 'false'.
float f = 1.0F/3.0F;
System.out.println( (f * 3.0F) == 1.0F );
Pond Lee
Greenhorn

Joined: Jan 20, 2001
Posts: 3
I think you are correct. I tried this code. The output is also TRUE.
Ken Pullin
Ranch Hand

Joined: Jan 29, 2001
Posts: 43
Thanks - I just wanted to make sure I wasn't looking at something wrong.
bill bozeman
Ranch Hand

Joined: Jun 30, 2000
Posts: 1070
I think the point of it is it will not always print true on every machine. Since float values lose precision, when you do 1.0F/3.0F you may get .333333333334 and then when you mutiply that by 3.0f you may get 1.00000000001 which won't equal 1.0f.
Bill
Tejas Nakawala
Ranch Hand

Joined: Jan 04, 2001
Posts: 80
Hi Ken,
Yes u r right,
When i tried to run the code on my machine it was 'True'.
So there may me a error with JQPlus.
Tejas Nakawala
Mukti Bajaj
Ranch Hand

Joined: Dec 11, 2000
Posts: 59
Hi guys,
I guess there is no error,
As the question is,"will the code below print, false"
So the answer has to be false....as you all know that, the code will print "true".
NO ERROR....it's the way you read the question
Mukti
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Error with JQPlus Question
 
Similar Threads
Floating Confusion
precision of double and float
float & JQ+ -- VELU
Doubt
Marcus Q1