java. signum_Java Long类signum()方法与示例

java. signum

长类signum()方法 (Long 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) of a long type.

    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(long value);

Parameter(s):

参数:

  • long value – represents the long value to be parsed.

    long value –表示要解析的long值。

Return value:

返回值:

The return type of this method is int, it returns the following values based on the following cases,

此方法的返回类型为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 Long class

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

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

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

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

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

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

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

Output

输出量

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


翻译自: https://www.includehelp.com/java/long-class-signum-method-with-example.aspx

java. signum

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值