The Wayback Machine - https://web.archive.org/web/20240204103746/https://www.geeksforgeeks.org/biginteger-signum-method-in-java/
Open In App
Related Articles

BigInteger signum() Method in Java

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

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 negative
  • returns 0 when number is zero
  • returns +1 when number is positive

Syntax:  

public int signum()

Parameters: The method does not take any parameters.
Return Value: The method returns -1, 0 or 1 as the value of this BigInteger when they are negative, zero or positive respectively.

Examples:  

Input: 2300 
Output: 1
Explanation: 2300 is positive number 
so the method returns 1

Input: -5482549 
Output: -1

Below program illustrate the signum() method of BigInteger. 

Java




// Program Demonstrate signum() method of BigInteger
 
import java.math.*;
 
public class GFG {
 
    public static void main(String[] args)
    {
        // Creating BigInteger object
        BigInteger biginteger = new BigInteger("2300");
 
        // Call signum() method on bigInteger
        // store the return value as int
        int sigvalue = biginteger.signum();
 
        // Depending upon sign value find sign of biginteger
        String sign = null;
        if (sigvalue == 0)
            sign = "zero";
        else if (sigvalue == 1)
            sign = "positive";
        else
            sign = "negative";
 
        // Defining result
        String result = "BigInteger " + biginteger + " is " +
        sign + " and Sing value is " + sigvalue;
 
        // Print result
        System.out.println(result);
    }
}


Output: 

BigInteger 2300 is positive and Sing value is 1

 

Reference:https://docs.oracle.com/javase/7/docs/api/java/math/BigInteger.html#signum()
 

Feeling lost in the vast world of Backend Development? It's time for a change! Join our Java Backend Development - Live Course and embark on an exciting journey to master backend development efficiently and on schedule.
What We Offer:

  • Comprehensive Course
  • Expert Guidance for Efficient Learning
  • Hands-on Experience with Real-world Projects
  • Proven Track Record with 100,000+ Successful Geeks

Last Updated : 12 May, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads
Complete Tutorials