Java.lang Package Classes

Java Long - signum() Method



The java.lang.Long.signum() method returns the signum function of the specified long 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(long i)

Parameters

i Specify the value whose signum is to be computed.

Return Value

Returns the signum function of the specified long value.

Exception

NA.

Example:

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

import java.lang.*;

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

    //printing the signum function of the long values 
    System.out.println("signum function of x is: " + Long.signum(x)); 
    System.out.println("signum function of y is: " + Long.signum(y)); 
    System.out.println("signum function of z is: " + Long.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 - Long