how to use isNaN() method of the Float class. - Java Language Basics

Java examples for Language Basics:float

Description

how to use isNaN() method of the Float class.

Demo Code


 
public class Main {
 
  public static void main(String[] args) {
   //  w  w  w.j av  a  2  s .  c  o  m
    /*
     It return true if the specified argument is Not-a-Number value, false otherwise.
    */
    float f = (float) Math.sqrt(-10);
    boolean b1 = Float.isNaN(f);
    System.out.println(b1);
 
    /*
     boolean isNaN() instance method checks whether the Float object is
     Not-a-Number value or not.
     It return true if the object is Not-a-Number value, false otherwise.
    */
    Float fObj = new Float(f);
    boolean b2 = fObj.isNaN();
    System.out.println(b2);
  }
}

Result


Related Tutorials