• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

wrappers

 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Which of the following statements is false ?

Options :

a . Math . min ( -0f , 0f ) == 0f
b . Math . round ( Long . MAX_VALUE + 1.5) == Long . MAX_VALUE
c . Math . round ( Integer . MIN_VALUE - 6.5 ) == Integer . MIN_VALUE
d . Math . round ( Integer . MIN_VALUE - 6.5f ) == Integer . MIN_VALUE

Answer : c

can anyone tell me why c returns false... and why others return true?

Thanks in advance..

rajani.
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rajani,

By default 6.5 is taken as double rathe than float. and Math.round has only two signatures:

static long round(double a)
static int round(float a)

So C should be the correct answer as the return value should be long.

Hopre that clarifies..
Abhishek
 
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello All,

But I do not know why Math.min(-0f, 0f) == 0f is true ?

Thanks,
Jack
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is the right answer. Check out the last senence out of the Java API in the paragraph below

"If one argument is positive zero and the other is negative zero, the result is negative zero."

BUT...

positive and negative zero are considered equal therefore
-0.0 < 0.0 is false and -0.0 <= 0.0 is true

So that is why (A) is true.

(C) is false as described above, becuase round only returns int and long and 6.5 would be converted to double which would convert Integer.MIN_VALUE to double which would return a long, not an int so Integer.MIN_VALUE would not be returned.

Whew... Hope that helps.
 
Rajani Sudhakar
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all...

Thankyou soo much for each of your replies.
I am satisfied.

Regards,
rajani.
 
yeah, but ... what would PIE do? Especially concerning this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic