一、
public class wqw { /**
 * @param args
 */
public static void main(String[] args) {
// TODO Auto-generated method stub
double i=9;
double j=0;
System.out.println(j%i);
}}
结果0.0
二、
public class wqw { /**
 * @param args
 */
public static void main(String[] args) {
// TODO Auto-generated method stub
double i=9;
double j=0;
System.out.println(i%j);
}}
结果NaN

解决方案 »

  1.   

    重数学角度来说 余数就是除不尽的数,而0不能做分母,所以9/0 是NaN是合理的
      

  2.   


    #include <stdio.h>
    int main()
    {
    double d = 9;
    double b = 0;
    double rst = d%b;
    printf("%f", d%b);
    return 0;
    }
    --------------------Configuration: test - Win32 Debug--------------------
    Compiling...
    test.cpp
    test.cpp(6) : error C2296: '%' : illegal, left operand has type 'double'
    test.cpp(6) : error C2297: '%' : illegal, right operand has type 'double'
    test.cpp(7) : error C2296: '%' : illegal, left operand has type 'double'
    test.cpp(7) : error C2297: '%' : illegal, right operand has type 'double'
    Error executing cl.exe.test.obj - 4 error(s), 0 warning(s)