Java BigInteger signum() method

The signum() method of Java BigInteger class is used to check whether a BigInteger value is positive, negative or zero. This method returns one of the following values depending on the following conditions :

  • This method returns 1 when this BigInteger is positive.
  • This method returns 0 when this BigInteger is zero.
  • This method returns -1 when this BigInteger is negative.

Syntax:

Parameter:

NA

Returns:

The method returns 1, 0 or -1 as the value of this BigInteger when they are positive, zero or negative respectively.

Exception:

NA

Example 1

Test it Now

Output:

For 10, Signum function returns 1

Example 2

Test it Now

Output:

For -10, Signum function returns -1

Example 3

Test it Now

Output:

For 0, Signum function returns 0

Next TopicJava BigInteger




Latest Courses