Advertisement
Guest User

Untitled

a guest
Feb 10th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.13 KB | None | 0 0
  1. BigNumber mult(BigNumber other) {
  2. String numero1 = "";
  3. String numero2 = "";
  4. int contador = 2;
  5. int ncarry = 0;
  6. int valorSumas = 0;
  7. int contadorUnidades = 0;
  8. BigNumber o;
  9. BigNumber o2;
  10.  
  11.  
  12. if (this.compareTo(other) == 0 || this.compareTo(other) == 1) {
  13.  
  14. n1 = this.container;
  15. n2 = other.container;
  16.  
  17.  
  18. } else {
  19.  
  20. n1 = other.container;
  21. n2 = this.container;
  22.  
  23. }
  24.  
  25. for (int i = n2.length() - 1; i >= 0; i--) {
  26. for (int j = n1.length() - 1; j >= 0; j--) {
  27.  
  28. valor = (n2.charAt(i) - 48) * (n1.charAt(j) - 48);
  29.  
  30. if (contador % 2 == 0) {
  31. if (carry) {
  32. valor = ((n2.charAt(i) - 48) * (n1.charAt(j) - 48) + ncarry);
  33. carry = false;
  34. }
  35. if (valor > 9) {
  36. carry = true;
  37. if (j == 0) {
  38. numero1 = valor + numero1;
  39. } else {
  40. ncarry = valor / 10;
  41. valor -= (ncarry * 10);
  42. numero1 = valor + numero1;
  43.  
  44. }
  45. } else {
  46. if (j == 0) {
  47. numero1 = valor + numero1;
  48. } else {
  49.  
  50. numero1 = valor + numero1;
  51. }
  52. }
  53. if (contadorUnidades >= 1) {
  54. for (int z = 0; z < contadorUnidades; z++) {
  55. numero1 += '0';
  56. }
  57.  
  58. }
  59.  
  60.  
  61. } else {
  62. if (carry) {
  63. valor = ((n2.charAt(i) - 48) * (n1.charAt(j) - 48) + ncarry);
  64. carry = false;
  65. }
  66. if (valor > 9) {
  67. carry = true;
  68. if (j == 0) {
  69. numero2 = valor + numero2;
  70. } else {
  71. ncarry = valor / 10;
  72. valor -= (ncarry * 10);
  73. numero2 = valor + numero2;
  74.  
  75. }
  76. } else {
  77. if (j == 0) {
  78. numero2 = valor + numero2;
  79. } else {
  80.  
  81. numero2 = valor + numero2;
  82. }
  83. }
  84. if (contadorUnidades >= 1 && j == 0) {
  85. for (int z = 0; z < contadorUnidades; z++) {
  86. numero2 += '0';
  87. }
  88.  
  89. }
  90. }
  91.  
  92.  
  93. }
  94. contadorUnidades++;
  95. contador++;
  96. carry = false;
  97.  
  98.  
  99. }
  100.  
  101. o = new BigNumber(numero1);
  102. o2 = new BigNumber(numero2);
  103.  
  104.  
  105. resultado += o.add(o2);
  106.  
  107.  
  108. return new BigNumber(resultado);
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement