当-a%b代表a,b =整数时,余数为0但如果a,b为double,则结果为-0

时间:2015-10-12 12:39:32

标签: java integer double

class TestSampl {
    public static void main(String[] args) {
        int a = -47, b = 47;
        double c = -333.0, d = 333.0;                                        
        //why does integer print output as 
        System.out.println("Integer " + a/b + " " + a%b );  
        // and double print output as -0
        System.out.println("Double " + c/d + " " + c%d );   
    }
}                                                  

1 个答案:

答案 0 :(得分:2)

您对整数模数还是双模数感到困惑?

没有-0整数,因此选择0的选项很少。然而,双打有正负零(更不用说正无穷大,负无穷大和NaN),所以对于双打,答案将是"因为它是如何定义的和" #34;