Guest User

Untitled

a guest
Mar 20th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. /*
  2. 取模(modulo)和取余(remainder)的区别
  3. a/b = c
  4. c 向上取整: 向+∞方向取最接近精确值的整数, 也就是取比实际结果稍大的最小整数, 也叫 Ceiling 取整
  5. c 向零取整: 向0方向取最接近精确值的整数, 换言之就是舍去小数部分, 因此又称截断取整 Truncate
  6. c 向下取整: 向-∞方向取最接近精确值的整数, 也就是取比实际结果稍小的最大整数, 也叫 Floor 取整
  7. */
  8.  
  9.  
  10. class Test {
  11. public static void main(String[] args) {
  12.  
  13. System.out.println("-7%3: " + -7 % 3);
  14. System.out.println("Math.floorMod(-7, 3): " + Math.floorMod(-7, 3));
  15.  
  16. System.out.println("------------------------");
  17.  
  18. System.out.println("7%-3: " + 7 % -3);
  19. System.out.println("Math.floorMod(7, -3): " + Math.floorMod(7, -3));
  20.  
  21. System.out.println("------------------------");
  22.  
  23. System.out.println("-7%4: " + -7 % 4);
  24. System.out.println("Math.floorMod(-7, 4): " + Math.floorMod(-7, 4));
  25. }
  26. }
Add Comment
Please, Sign In to add comment