Home » Java programming language

Java Integer class signum() method with example

Integer class signum() method: Here, we are going to learn about the signum() method of Integer class with its syntax and example.
Submitted by Preeti Jain, on October 02, 2019

Integer class signum() method

  • signum() method is available in java.lang package.
  • signum() method is used to returns the signum(sign number) function of the given argument (value).
  • signum() method is a static method, it is accessible with the class name too and if we try to access the method with the class object then also we will not get an error.
  • signum() method does not throw an exception at the time of returning signum function.

Syntax:

    public static int signum(int value);

Parameter(s):

  • int value – represents the integer value to be parsed.

Return value:

The return type of this method is int, it returns three integer values depend on the following conditions,

  • If we pass "Negative Values", it returns -1.
  • If we pass "Positive Values", it returns 1.
  • If we pass "Zero Values", it returns 0.

Example:

// Java program to demonstrate the example 
// of signum(int value) method of
// Integer class

public class SignumOfIntegerClass {
    public static void main(String[] args) {
        int value1 = 100;
        int value2 = 0;
        int value3 = -100;

        // By using signum(value1) , it returns 1 because the passing
        // parameter holds the value is greater than 0
        int result = Integer.signum(value1);

        // Display result
        System.out.println("Integer.signum(value1): " + Integer.signum(value1));

        // By using signum(value2) , it returns 0 because the passing
        // parameter holds the value is equals to 0
        result = Integer.signum(value2);

        // Display result
        System.out.println("Integer.signum(value2): " + Integer.signum(value2));

        // By using signum(value3) , it returns -1 because the passing
        // parameter holds the value is less than 0
        result = Integer.signum(value3);

        // Display result
        System.out.println("Integer.signum(value3): " + Integer.signum(value3));
    }
}

Output

Integer.signum(value1): 1
Integer.signum(value2): 0
Integer.signum(value3): -1





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.