java. signum
整数类signum()方法 (Integer class signum() method)
signum() method is available in java.lang package.
signum()方法在java.lang包中可用。
signum() method is used to returns the signum(sign number) function of the given argument (value).
signum()方法用于返回给定参数(值)的signum(符号数)函数。
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()方法是静态方法,也可以使用类名进行访问,如果尝试使用类对象访问该方法,则也不会出错。
signum() method does not throw an exception at the time of returning signum function.
在返回signum函数时, signum()方法不会引发异常。
Syntax:
句法:
public static int signum(int value);
Parameter(s):
参数:
int value – represents the integer value to be parsed.
int value –表示要解析的整数值。
Return value:
返回值:
The return type of this method is int, it returns three integer values depend on the following conditions,
此方法的返回类型为int ,它根据以下条件返回三个整数值:
If we pass "Negative Values", it returns -1.
如果传递“负值”,则返回-1。
If we pass "Positive Values", it returns 1.
如果我们传递“正值”,则返回1。
If we pass "Zero Values", it returns 0.
如果传递“零值”,则返回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
翻译自: https://www.includehelp.com/java/integer-class-signum-method-with-example.aspx
java. signum