• 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
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

Math.abs() question

 
Ranch Hand
Posts: 42
  • 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 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.
 
Ranch Hand
Posts: 522
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is why

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

The issue is discussed here
 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

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



I think this is only case where the abs() method returns the negative value.
 
Vicken Karaoghlanian
Ranch Hand
Posts: 522
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
    Posts: 52
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hi Vicken,

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

    Bartenders may please close this topic.!

    Thanks
     
    reply
      Bookmark Topic Watch Topic
    • New Topic