Check if a Float is not-a-number with isNaN method in Java
Description
The following code shows how to check if a Float is not-a-number with isNaN method.
Example
/*w ww .java2 s . com*/
public class Main {
public static void main(String[] args) {
float f = (float) Math.sqrt(-10);
boolean b1 = Float.isNaN(f);
System.out.println(b1);
Float fObj = new Float(f);
boolean b2 = fObj.isNaN();
System.out.println(b2);
}
}
The code above generates the following result.
Home »
Java Tutorial »
Java Data Type »
Java Tutorial »
Java Data Type »