abdukodir

Untitled

Dec 16th, 2015
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. package MailTask;
  2.  
  3. import java.util.Arrays;
  4.  
  5. /**
  6. * Created by qurbonzoda on 16.12.15.
  7. */
  8. public class BigNum {
  9. public static int SIZE = 100000;
  10. public static int BASE = 10;
  11. private char[] value = new char[SIZE];
  12.  
  13. public BigNum() {
  14. }
  15. public BigNum(String string) {
  16. for (int i = 0; i < string.length(); i++) {
  17. value[string.length() - i - 1] = string.charAt(i);
  18. }
  19. }
  20. public BigNum(BigNum other) {
  21. value = Arrays.copyOf(other.value, SIZE);
  22. }
  23.  
  24. public boolean equals(BigNum other) {
  25. return Arrays.equals(value, other.value);
  26. }
  27.  
  28. public boolean isZero() {
  29. return equals(new BigNum());
  30. }
  31.  
  32. @Override
  33. public String toString() {
  34. int last = lastNonZero();
  35. // if (last == 0) return "0";
  36. String string = new String(value, 0, last);
  37. StringBuilder stringBuilder = new StringBuilder(string);
  38. stringBuilder.reverse();
  39. return stringBuilder.toString();
  40. }
  41.  
  42. private int lastNonZero() {
  43. int last = 0;
  44. for (int i = 0; i < value.length; i++) {
  45. if (value[i] != 0) {
  46. last = i + 1;
  47. }
  48. }
  49. return last;
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment