Tutorials Point


  Java Basics
  Java Object Oriented
  Java Advanced
  Java Useful References
  Java Useful Resources
  Selected Reading

© 2011 TutorialsPoint.COM


  Home     References     Discussion Forums     About TP  

Java - abs() Method


previous next AddThis Social Bookmark Button


Description:

The method gives the absolute value of the argument. The argument can be int, float, long, double, short, byte.

Syntax:

All the variant of this method are given below:

double abs(double d)
float abs(float f)
int abs(int i)
long abs(long lng)

Parameters:

Here is the detail of parameters:

  • Any primitive data type

Return Value :

  • Returns the absolute value of the argument.

Example:

public class Test{ 
   public static void main(String args[]){
      Integer a = -8;
      double d = -100;
      float f = -90;    
						
      System.out.println(Math.abs(a));
      System.out.println(Math.abs(d));     
      System.out.println(Math.abs(f));    
   }
}

This produces following result:

8
100.0
80.0


previous next Printer Friendly



  

Advertisement

Online Image Processing

Indian Baby Names