Java – Math signum() Example, Math signum() Function

Math class is part of java.lang package. Math signum method returns the argument either 1.0 or -1.0. If argument value is less than zero, it will return -1.0 value and argument is greater than zero or zero, it will return 1.0. signum function return type is double or float.

Math signum example explains how to use Math signum function in java.

public class JavaMathSignumExample {

    public static void main(String[] args) {

        double E1 = Math.signum(2323.4393086905318781);

        double E2 = Math.signum(0);

        double E3 = Math.signum(-2323.8393086905318781);

        System.out.println("Math signum value :"+E1);
        System.out.println("Math signum value :"+E2);
        System.out.println("Math signum value :"+E3);
    }
}

Output

Math signum value :1.0
Math signum value :0.0
Math signum value :-1.0

Tags:

Bookmark  

 

Leave a Reply

Security Code:

 

  Random Post