Java Integer signum() method
The signum() method of Java Integer class returns the signum function of the specified int value. Syntax public static int signum (int i) Parameters The parameter ‘i’ represents the value whose signum is to be determined. Return Value This method returns the signum function of the specified int value.
- It returns -1, if the specified int value is negative.
- It returns 0, if the specified int value is zero.
- It returns 1, if the specified int value is positive.
public class JavaIntegerSignumExample1 { public static void main(String[] args) { Integer val=78; //it returns 1 for positive value of the argument int signum=Integer.signum(val); System.out.println(signum); } }Output
1Example 2
public class JavaIntegerSignumExample2 { public static void main(String[] args) { Integer val=-0; //It returns 0, if the specified int value is zero int signum=Integer.signum(val); System.out.println(signum); } }Output
0Example 3
public class JavaIntegerSignumExample3 { public static void main(String[] args) { Integer val=-9; //It returns -1, if the specified int value is negative int signum=Integer.signum(val); System.out.println(signum); } }Output
-1