Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- 取模(modulo)和取余(remainder)的区别
- a/b = c
- c 向上取整: 向+∞方向取最接近精确值的整数, 也就是取比实际结果稍大的最小整数, 也叫 Ceiling 取整
- c 向零取整: 向0方向取最接近精确值的整数, 换言之就是舍去小数部分, 因此又称截断取整 Truncate
- c 向下取整: 向-∞方向取最接近精确值的整数, 也就是取比实际结果稍小的最大整数, 也叫 Floor 取整
- */
- class Test {
- public static void main(String[] args) {
- System.out.println("-7%3: " + -7 % 3);
- System.out.println("Math.floorMod(-7, 3): " + Math.floorMod(-7, 3));
- System.out.println("------------------------");
- System.out.println("7%-3: " + 7 % -3);
- System.out.println("Math.floorMod(7, -3): " + Math.floorMod(7, -3));
- System.out.println("------------------------");
- System.out.println("-7%4: " + -7 % 4);
- System.out.println("Math.floorMod(-7, 4): " + Math.floorMod(-7, 4));
- }
- }
Add Comment
Please, Sign In to add comment