• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

abs( ) method

 
k j goban
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what will be the o/p for the following and why
pls give me the explanation.
class Test
{
public static void main(String[] args)
{
System.out.println(Math.abs(Integer.MIN_VALUE));
}
}
thanks
with rgds
 
Anshuman Acharya
Ranch Hand
Posts: 144
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Integer.MIN_VALUE = -2147483648
Integer.MAX_VALUE = 2147483647
hence the abs of min-value is out of the range of the int primitive, ansd since they run about in a circle, the o/p goes rigth to the lowest value after crossing the highest one. i.e we effectively get Integer.MIN_VALUE BACK !
 
Balu Ramachandran
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
Answewr is : -2147483648
abs() returns absolute value of the given argument.
but hear min. value for Integer wrapper exceeds. it is a cyclic process so that only u got above answer.
------------------
R.Balu
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic