nan就是无法表示的值
例如:
对负数开平方根结果就是nan

解决方案 »

  1.   

    那下面这个程序为什么没有输出结果啊
    public class SL275
    {
      public static void main(String[] args)
      {
        double d1=-234;
        double d2=Math.sqrt(d1);
        if (d2==Double.NaN)
        {
          System.out.println("d2="+Double.NaN);
        }
      }
    }
      

  2.   

    isNaN
    public static boolean isNaN(double v)Returns true if the specified number is the special Not-a-Number (NaN) value.
    Parameters:
    v - the value to be tested.
    Returns:
    true if the value of the argument is NaN; false otherwise.
      

  3.   

    NaN代表不能表示的数,具体的数就不一定了,你也不能说sqrt(-1)==sqrt(-2)吧。
    这样改
    public class SL275
    {
      public static void main(String[] args)
      {
        double d1=-234;
        double d2=Math.sqrt(d1);
        System.out.println(d2);
      }