float isnan
Syntax:
句法:
public boolean isNaN ();
public static boolean isNaN(float value);
浮动类isNaN()方法 (Float class isNaN() method)
isNaN() method is available in java.lang package.
isNaN()方法在java.lang包中可用。
isNaN() method is used to check NaN values (i.e. either positive NaN or negative NaN).
isNaN()方法用于检查NaN值(即正NaN或负NaN)。
isNaN(float value) method is used to check NaN values for the given float argument (i.e. either positive or negative NaN).
isNaN(float value)方法用于检查给定float参数的NaN值(即正或负NaN)。
isNaN() method does not throw an exception at the time of checking NaN values represented by the object.
在检查对象表示的NaN值时, isNaN()方法不会引发异常。
Similarly, the isNaN(float value) method does not throw an exception at the time of checking NaN values of the given argument.
同样, isNaN(float value)方法在检查给定参数的NaN值时也不会引发异常。
They 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.
它们是非静态方法,只能通过类对象访问,如果尝试使用类名称访问方法,则会收到错误消息。
Parameter(s):
参数:
In the first case isNaN(), we don't pass any parameter or value.
在第一种情况下, isNaN() ,我们不传递任何参数或值。
In the second case isNaN(float value), we pass only one parameter of the float type it represents the float value to be tested for NaN.
在第二种情况下是NaN (float value) ,我们仅传递一个float类型的参数,该参数表示要测试的NaN浮点值。
Return value:
返回值:
In the first case, the return type of this method is boolean, it returns a boolean value either true or false depending on the following cases,
在第一种情况下,此方法的返回类型为boolean ,它根据以下情况返回布尔值true或false,
If the value represented by the object is either positive NaN or negative NaN, it returns true.
如果对象表示的值是正NaN或负NaN,则返回true。
Else, if the value represented by the object is not either positive NaN or negative NaN, it returns false.
否则,如果对象表示的值不是正NaN或负NaN,则返回false。
In the second case, The return type of this method is boolean, it returns boolean value either true or false depending on the following case,
在第二种情况下,此方法的返回类型为boolean ,它根据以下情况返回布尔值true或false;
If the given argument value is either positive NaN or negative NaN, it returns true.
如果给定的参数值是正NaN或负NaN,则返回true。
Else, if the given argument value is not either positive NaN or negative NaN, it returns false.
否则,如果给定的参数值不是正NaN或负NaN,则返回false。
Example:
例:
// Java program to demonstrate the example
// of isNaN() method of Float class
public class IsNaNOfFloatClass {
public static void main(String[] args) {
// Object initialization
Float ob1 = new Float(0.0 / 0.0);
Float ob2 = new Float(-0.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 NaN by calling ob1.isNaN() for ob1
// and ob2.isNaN() for ob2
boolean NaN1 = ob1.isNaN();
boolean NaN2 = ob2.isNaN();
// It also checks for NaN of this Float object by calling
// Float.isNaN(ob3) for ob3
boolean NOTNaN = ob3.isNaN(ob3);
// Display result values
System.out.println("ob1.isNaN(): " + NaN1);
System.out.println("ob2.isNaN(): " + NaN2);
System.out.println("Float.isNaN(ob3): " + NOTNaN);
}
}
Output
输出量
ob1 :NaN
ob2: NaN
ob3: 20.0
ob1.isNaN(): true
ob2.isNaN(): true
Float.isNaN(ob3): false
翻译自: https://www.includehelp.com/java/float-class-isnan-method-with-example.aspx
float isnan