Syntax error Integer.signum() method in Java

Integer.signum() method in Java



The method returns the signum function of the specified int value. Let us now see the syntax.

int signum(int i)

Here is the parameter.

  • i − This is the int 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.

Let us now see an example.

Example

 Live Demo

public class Demo {
   public static void main(String []args) {
      System.out.println("Returns = "+Integer.signum(0));
      System.out.println("Returns = "+Integer.signum(-99));
      System.out.println("Returns = "+Integer.signum(678));
   }
}

Output

Returns = 0
Returns = -1
Returns = 1
Updated on: 2020-06-26T10:39:47+05:30

149 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements