编程语言
首页 > 编程语言> > Java基础中 % 运算的本质

Java基础中 % 运算的本质

作者:互联网

Java的取余运算

本质是执行:a % b = a - a / b * b

double num1 = 10 % 3;
double num2 = (-10) % 3;
double num3 = 10 % (-3);
double num4 = (-10) % (-3);
System.out.println("num1 = " + num1);
System.out.println("num2 = " + num2);
System.out.println("num3 = " + num3);
System.out.println("num4 = " + num4);

运行截图

 

标签:num4,10,Java,运算,double,System,本质,println,out
来源: https://www.cnblogs.com/xiaobaiyuan/p/15601913.html