Java.lang Package Classes

Java Integer - signum() Method



The java.lang.Integer.signum() method returns the signum function of the specified int value. (The return value is -1 if the specified value is negative; 0 if the specified value is zero; and 1 if the specified value is positive.)

Syntax

public static int signum(int i)

Parameters

i Specify the value whose signum is to be computed.

Return Value

Returns the signum function of the specified int value.

Exception

NA.

Example:

In the example below, the java.lang.Integer.signum() method returns the signum function of the specified int value.

import java.lang.*;

public class MyClass {
  public static void main(String[] args) {
    
    //creating int values
    int x = 5;
    int y = 0;
    int z = -5;

    //printing the signum function of the int values 
    System.out.println("signum function of x is: " + Integer.signum(x)); 
    System.out.println("signum function of y is: " + Integer.signum(y)); 
    System.out.println("signum function of z is: " + Integer.signum(z)); 
  }
}

The output of the above code will be:

signum function of x is: 1
signum function of y is: 0
signum function of z is: -1

❮ Java.lang - Integer