isinfinite_Java Float类isInfinite()方法与示例

isinfinite

Syntax:

句法:

    public boolean isInfinite ();
    public static boolean isInfinite (float value);

浮动类isInfinite()方法 (Float class isInfinite() method)

  • isInfinite() method is available in java.lang package.

    isInfinite()方法在java.lang包中可用。

  • isInfinite() method is used to check the infinity of this Float object (i.e. either positive infinity or negative infinity).

    isInfinite()方法用于检查此Float对象的无穷大(即正无穷大或负无穷大)。

  • isInfinite(float value) method is used to check the infinity of the given argument is of float type (i.e. either positive infinity or negative infinity).

    isInfinite(float value)方法用于检查给定参数的无穷大为 float类型(即正无穷大或负无穷大)。

  • These are non-static methods, they are accessible with the class object only and if we try to access the method with the class name then we will get an error.

    这些是非静态方法,只能通过类对象访问,如果尝试使用类名称访问该方法,则会收到错误消息。

  • These methods do not throw an exception at the time of checking infinity.

    这些方法在检查无穷大时不会引发异常。

Parameter(s):

参数:

  • In the First case – isInfinite(), we don't pass any parameter or value.

    在第一种情况下– isInfinite() ,我们不传递任何参数或值。

  • In the Second case – isInfinite(float value), we pass only one parameter or value is of float type.

    在第二种情况下-isInfinite(float value) ,我们仅传递一个参数或value为float类型。

Return value:

返回值:

The return type of this method is boolean, it returns a boolean value either true or false depending on the condition.

此方法的返回类型为boolean ,它根据条件返回布尔值true或false。

  • In the first case, if the given value represented by the object is either positive infinity or negative infinity, it returns true.

    在第一种情况下,如果对象表示的给定值是正无穷大或负无穷大,则返回true。

  • In the second case, if the given value represented by the object is not either positive infinity or negative infinity, it returns false.

    在第二种情况下,如果对象表示的给定值不是正无穷大或负无穷大,则返回false。

Example:

例:

// Java program to demonstrate the example 
// of isInfinite() method of Float class

public class IsInfiniteOfFloatClass {
    public static void main(String[] args) {
        // Object initialization
        Float ob1 = new Float(10.0 / 0.0);
        Float ob2 = new Float(-20.0 / 0.0);
        Float ob3 = new Float(20.0);

        // Display ob1,ob2 and ob3 values
        System.out.println("ob1: " + ob1);
        System.out.println("ob2: " + ob2);
        System.out.println("ob3: " + ob3);

        // It checks infinity by calling ob1.isInfinite() for ob1
        // and ob2.isInfinite() for ob2  

        boolean infinite1 = ob1.isInfinite();
        boolean infinite2 = ob2.isInfinite();

        // Display result values
        System.out.println("ob1.isInfinite(): " + infinite1);
        System.out.println("ob2.isInfinite(): " + infinite2);

        // It checks infinity by calling Float.isInfinite(ob3) for ob3
        boolean infinite3 = Float.isInfinite(ob3);

        // Display result values
        System.out.println("Float.isInfinite(ob3): " + infinite3);
    }
}

Output

输出量

ob1: Infinity
ob2: -Infinity
ob3: 20.0
ob1.isInfinite(): true
ob2.isInfinite(): true
Float.isInfinite(ob3): false


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

isinfinite

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值