Home Java Java-get-example Get Absolute Value



Get Absolute Value
Posted on: October 22, 2008 at 12:00 AM
Absolute value is the only value of a number regardless of a prefixed plus or minus sign.

Get Absolute Value

     

Absolute value is the only value of a number regardless of a prefixed plus or minus sign. In the example given below we have used abs() method of class java.lang.Math that returns absolute value  of a given number as argument. We can use abs() method for double, float, int, long type values.

 

 

 

 

public class GetAbsoluteValue {
 public static void main(String args[]) throws Exception {
  double value = Math.abs(-10);
  double value1=Math.abs(50);
  System.out.println("The absolute value of -10 is: "+value);
  System.out.println("The absolute value for the condition is: "+value1);
  }
}

Output will be displayed as:

Download Source Code

Related Tags for Get Absolute Value:
javacmathclassmethodsedvaluenumberreturnexamplerdlexamprefixrefargumentlanfixedesignuseabsoluteinasmntminminusminusminlessjclesmexaxampsurnxesoessatishaivmplpreplusarvassrdthavbeloabaluhatfixgapleplprmionlyonolonl


More Tutorials from this section

Ask Questions?    Discuss: Get Absolute Value   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.