Open In App

Integer signum() Method in Java

Last Updated : 19 Aug, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

The signum function is an odd mathematical function that extracts the sign of a real number. The signum function is also known as sign function. 
The Integer.signum() method of java.lang returns the signum function of the specified integer value. For a positive value, a negative value and zero the method returns 1, -1 and 0 respectively.

Syntax : 

public static int signum(int a)

Parameter: The method takes one parameter a of integer type on which the operation is to be performed.

Return Value: The method returns the signum function of the specified integer value. If the specified value is negative it returns -1, 0 if the specified value is zero, and 1 if the specified value is positive.

Examples:  

Consider an integer a = 27
Since 27 is a positive int signum will return= 1
        
Consider another integer a = -61
Since -61 is a negative int signum will return= -1
     
Consider the integer value a = 0
For a zero signum, it will return = 0 

Below programs illustrate the Java.lang.Integer.signum() Method: 

Program 1:  

Java




// Java program to illustrate the
// Java.lang.Integer.signum() Method
import java.lang.*;
 
public class Geeks {
 
public static void main(String[] args) {
 
    // It will return 1 as  the int value is greater than 1
    System.out.println(Integer.signum(1726));
 
    // It will return -1 as  the int value is less than 1
    System.out.println(Integer.signum(-13));
 
    // It will returns 0 as int value is equal to 0
    System.out.println(Integer.signum(0));
}
}


Output: 

1
-1
0

 

Program 2: 

Java




// Java program to illustrate the
// Java.lang.Integer.signum() Method
import java.lang.*;
 
public class Geeks {
 
public static void main(String[] args) {
 
    // It will return 1 as  the int value is greater than 1
    System.out.println(Integer.signum(-1726));
 
    // It will return -1 as  the int value is less than 1
    System.out.println(Integer.signum(13));
 
    // It will returns 0 as int value is equal to 0
    System.out.println(Integer.signum(0));
}
}


Output: 

-1
1
0

 

Program 3: For a decimal value and string. 
Note: It returns an error message when a decimal value and string is passed as an argument.

Java




// Java program to illustrate the
// Java.lang.Integer.signum() Method
import java.lang.*;
 
public class Geeks {
 
public static void main(String[] args) {
 
    //returns compile time error as passed argument is a decimal value
    System.out.println(Integer.signum(3.81));
     
     
    //returns compile time error as passed argument is a string
    System.out.println(Integer.signum("77"));
 
 
}
}


Output: 

prog.java:10: error: incompatible types: possible lossy conversion from double to int
    System.out.println(Integer.signum(3.81));
                                      ^
prog.java:14: error: incompatible types: String cannot be converted to int
    System.out.println(Integer.signum("77"));
                                      ^
Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output
2 errors

 



Previous Article
Next Article

Similar Reads

BigInteger signum() Method in Java
prerequisite : BigInteger Basics The java.math.BigInteger.signum() method helps us to identify whether a BigInteger is positive or zero or negative. It returns one of the following values depending on the following conditions: returns -1 when number is negativereturns 0 when number is zeroreturns +1 when number is positive Syntax: public int signum
2 min read
Java signum() method with Examples
The java.lang.Math.signum() returns the Sign function of a value passed to it as argument. The signum() function returns the following values depending on the argument passed to it: If the argument passed is greater than zero, then the signum() function will return 1.0. If the argument passed is equal to zero, then the signum() function will return
2 min read
BigDecimal signum() Method in Java
The java.math.BigDecimal.signum() is an inbuilt method in Java that returns the signum function of this BigDecimal. The sign function or signum function is an odd mathematical function that extracts the sign of a real number. In mathematical expressions, the sign function is often represented as sgn. Syntax: public int signum() Parameters: This met
2 min read
Long signum() Method in Java
The signum function also known as sign function is an odd mathematical function that extracts the sign of a real number. The java.lang.Long.signum() method is used to get the signum function of the specified long value. For a positive value, a negative value and zero, the method returns 1, -1 and 0 respectively. Syntax : public static int signum(lo
2 min read
StrictMath signum() Method in Java
The signum(double num) is an inbuilt method of StrictMath class in Java which is used to get the signum method of the argument which means: The result is zero if the argument is zero. The result 1.0 when the argument is greater than zero. The result is -1.0 if the argument is less than zero. Syntax : public static double signum(double num) Paramete
3 min read
Java Program to Convert Integer List to Integer Array
There are many ways to convert integer List to ArrayList where in this article we will be discussing out 2 approaches as below: Using concept od streams in Java8Using Apache Commons LangUsing Guava Library Method 1: Using concept od streams in Java8 So, first, we will get to know about how to convert integer list to array list using java 8. In java
3 min read
Program to Convert Set of Integer to Array of Integer in Java
Java Set is a part of java.util package and extends java.util.Collection interface. It does not allow the use of duplicate elements and at max can accommodate only one null element. A Stream is a sequence of objects that supports various methods which can be pipelined to produce the desired result. Java 8 Stream API can be used to convert Set to Se
2 min read
Integer.MAX_VALUE and Integer.MIN_VALUE in Java with Examples
Most of the times, in competitive programming, there is a need to assign the variable, the maximum or minimum value that data type can hold, but remembering such a large and precise number comes out to be a difficult job. Therefore, Java has constants to represent these numbers, so that these can be directly assigned to the variable without actuall
3 min read
Converting Integer-String HashMap to String-Array-Integer HashMap in Java
Efficient Conversion of a HashMap<Integer, String> into another HashMap<String, Integer[]> involves organizing integer keys based on their corresponding string values. Here's a concise and efficient Java method to accomplish this transformation, focusing on clear and straightforward implementation. Step-by-Step Implementation of Convers
3 min read
Integer.valueOf() vs Integer.parseInt() with Examples
Integer.parseInt():While operating upon strings, there are times when we need to convert a number represented as a string into an integer type. The method generally used to convert String to Integer in Java is parseInt(). This method belongs to Integer class in java.lang package. It takes a valid string as a parameter and parses it into primitive d
4 min read
Practice Tags :