How to calculate and print Signum function of a number in Java using Math class ?.

Program to calculate and print Signum function of a number in Java using Math class.

package com.hubberspot.code;

public class SignumDemo {

 public static void main(String[] args) {
  
  // Creating three ints variable holding 
  // a negative integer, a positive integer
  // and 0 integer.
  
  int zero = 0;
  int positive = 10;
  int negative = -20;
  
  // Signum function calculates and returns following : 
  // for zero value it returns 0.0
  // for positive value it returns 1.0
  // for negative value it returns -1.0
  
  double zeroSign = Math.signum(zero);
  double positiveSign = Math.signum(positive);
  double negativeSign = Math.signum(negative);

  // printing the values of signum function of integers
  
  System.out.println("Signum of " + zero + " is " + zeroSign);
                System.out.println("Signum of " + negative + " is " + negativeSign);
                System.out.println("Signum of " + positive + " is " + positiveSign);

 }

}




Output of the program :