Advertisement
Guest User

Untitled

a guest
Jun 26th, 2015
1,444
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. /**
  2. * Divides {@code n} by 2.
  3. *
  4. * @param n
  5. * {@code NaturalNumber} to be divided
  6. * @updates n
  7. * @ensures 2 * n <= #n < 2 * (n + 1)
  8. */
  9. private static void divideBy2(NaturalNumber n) {
  10. int lastDigit = 0;
  11. if (!n.isZero()) {
  12. lastDigit = n.divideBy10();
  13. if (!n.isZero()) {
  14. int remainder2 = n.divideBy10();
  15. if (remainder2 % 2 != 0) {
  16. lastDigit = lastDigit / 2 + 5;
  17.  
  18. } else {
  19. lastDigit = lastDigit / 2;
  20. }
  21.  
  22. divideBy2(n);
  23. n.multiplyBy10(lastDigit);
  24.  
  25. } else {
  26. lastDigit = lastDigit / 2;
  27. }
  28. }
  29. n.multiplyBy10(lastDigit);
  30.  
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement