wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Math.abs() question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Math.abs() question" Watch "Math.abs() question" New topic
Author

Math.abs() question

Grady Jamyson
Ranch Hand

Joined: Aug 04, 2002
Posts: 42
Which of the following statements are true in terms of the java.lang.Math.abs method?

a. Four overloaded versions of abs exist.
b. An ArithmeticException is declared in the throws clause.
c. The type of the return value depends on the argument type.
d. The returned value is always of a floating-point primitive type.
e. If the argument is a negative integral value, then the returned value is always positive.
f. If the argument is positive, then the argument is returned.


the answers are: a,c,f
But I think e could be true.
Why e is not one of answers?

Thanks.
Vicken Karaoghlanian
Ranch Hand

Joined: Jul 21, 2003
Posts: 522
This is why

Math.abs(Integer.MIN_VALUE); // This will return -2147483648

The issue is discussed here


- Do not try and bend the spoon. That's impossible. Instead, only try to realize the truth. - What truth? - That there is no spoon!!!
Vicky Jain
Ranch Hand

Joined: Aug 02, 2003
Posts: 52
Hi,

Math.abs(Integer.MIN_VALUE); // This will return -2147483648


I think this is only case where the abs() method returns the negative value.


SCJP1.4(96%)<br />A drop of ink can make millions think.
Vicken Karaoghlanian
Ranch Hand

Joined: Jul 21, 2003
Posts: 522
Originally posted by Vicky Jain:
I think this is only case where the abs() method returns the negative value.

There are TWO cases in which abs will return -ve value
  • Math.abs(Integer.MIN_VALUE);
  • Math.abs(Long.MIN_VALUE);


  • For more info about the abs methods you can always read the API Documentaion here
    [ September 02, 2004: Message edited by: Vicken Karaoghlanian ]
    Vicky Jain
    Ranch Hand

    Joined: Aug 02, 2003
    Posts: 52
    Hi Vicken,

    Now i got it and thanks for correcting me man!!

    Bartenders may please close this topic.!

    Thanks
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Math.abs() question