Home »
Java programming language
Java - Integer Class signum() Method
Integer class signum() method: Here, we are going to learn about the signum() method of Integer class with its syntax and example.
By Preeti Jain Last updated : March 18, 2024
Integer 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).
- 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(int value);
Parameters
- int value – represents the integer value to be parsed.
Return Value
The return type of this method is int, it returns three integer values depend on the following conditions,
- 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
// Integer class
public class SignumOfIntegerClass {
public static void main(String[] args) {
int value1 = 100;
int value2 = 0;
int value3 = -100;
// By using signum(value1) , it returns 1 because the passing
// parameter holds the value is greater than 0
int result = Integer.signum(value1);
// Display result
System.out.println("Integer.signum(value1): " + Integer.signum(value1));
// By using signum(value2) , it returns 0 because the passing
// parameter holds the value is equals to 0
result = Integer.signum(value2);
// Display result
System.out.println("Integer.signum(value2): " + Integer.signum(value2));
// By using signum(value3) , it returns -1 because the passing
// parameter holds the value is less than 0
result = Integer.signum(value3);
// Display result
System.out.println("Integer.signum(value3): " + Integer.signum(value3));
}
}
Output
Integer.signum(value1): 1
Integer.signum(value2): 0
Integer.signum(value3): -1