Java Data Type Tutorial - Java StrictMath.abs(float a)








Syntax

StrictMath.abs(float a) has the following syntax.

public static float abs(float a)

Example

In the following code shows how to use StrictMath.abs(float a) method.

public class Main {
/*  w ww.j  a  v  a  2  s.  c o  m*/
  public static void main(String[] args) {
  
    float f1 = 12, f2 = -1;
    
    System.out.println("absolute value of " + f1 + " = " + 
        StrictMath.abs(f1));
   
    System.out.println("absolute value of " + f2 + " = " + 
        StrictMath.abs(f2));
  }
}

The code above generates the following result.