Java - Long Class signum() Method

Long class signum() method: Here, we are going to learn about the signum() method of Long class with its syntax and example. By Preeti Jain Last updated : March 20, 2024

Long class signum() method

  • signum() method is available in java.lang package.
  • signum() method is used to returns the signum(sign number) function of the given argument (value) of a long type.
  • signum() method is a static method, it is accessible with the class name too and if we try to access the method with the class object then also we will not get an error.
  • signum() method does not throw an exception at the time of returning signum function.

Syntax

    public static int signum(long value);

Parameters

  • long value – represents the long value to be parsed.

Return Value

The return type of this method is int, it returns the following values based on the following cases,

  • If we pass "Negative Values", it returns -1.
  • If we pass "Positive Values", it returns 1.
  • If we pass "Zero Values", it returns 0.

Example

// Java program to demonstrate the example 
// of signum(int value) method of Long class

public class SignumOfLongClass {
    public static void main(String[] args) {
        long value1 = 100;
        long value2 = 0;
        long value3 = -100;

        // By using signum(value1) , it returns 1 because the passing
        // parameter holds the value is greater than 0
        int result = Long.signum(value1);

        // Display result
        System.out.println("Long.signum(value1): " + Long.signum(value1));

        // By using signum(value2) , it returns 0 because the passing
        // parameter holds the value is equals to 0
        result = Long.signum(value2);

        // Display result
        System.out.println("Long.signum(value2): " + Long.signum(value2));

        // By using signum(value3) , it returns -1 because the passing
        // parameter holds the value is less than 0
        result = Long.signum(value3);

        // Display result
        System.out.println("Long.signum(value3): " + Long.signum(value3));
    }
}

Output

Long.signum(value1): 1
Long.signum(value2): 0
Long.signum(value3): -1

Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.