3.5 运算符

    在Java中,使用算术运算符+、-、*、/ 表示加、减、乘、除运算。当参与/运算的两个操作数都是整数时,表示整数除法;否则,表示浮点除法。
    整数的求余(取模)操作用%表示。
 
            int a = 3;
            int b = 6;
            
            System.out.println(a / b);    // 输出 0 
            System.out.println(b / a);    // 输出 2
                        System.out.println(b % a);   // 输出 0
 
            double c = 6.0;
            System.out.println(a / c);     //输出 0.5
            System.out.println(c / a);     //输出 2.0
            System.out.println(c % a);    //输出 0.0
 
    需要注意,整数被0除将会产生一个异常,而浮点数被0除将会得到一个无穷大或NaN。
            System.out.println( a / 0);     //Exception in thread "main" java.lang.ArithmeticException: / by zero
            System.out.println( c / 0);     //Infinity        
原文地址:https://www.cnblogs.com/avention/p/10024141.html