Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- BigNumber mult(BigNumber other) {
- String numero1 = "";
- String numero2 = "";
- int contador = 2;
- int ncarry = 0;
- int valorSumas = 0;
- int contadorUnidades = 0;
- BigNumber o;
- BigNumber o2;
- if (this.compareTo(other) == 0 || this.compareTo(other) == 1) {
- n1 = this.container;
- n2 = other.container;
- } else {
- n1 = other.container;
- n2 = this.container;
- }
- for (int i = n2.length() - 1; i >= 0; i--) {
- for (int j = n1.length() - 1; j >= 0; j--) {
- valor = (n2.charAt(i) - 48) * (n1.charAt(j) - 48);
- if (contador % 2 == 0) {
- if (carry) {
- valor = ((n2.charAt(i) - 48) * (n1.charAt(j) - 48) + ncarry);
- carry = false;
- }
- if (valor > 9) {
- carry = true;
- if (j == 0) {
- numero1 = valor + numero1;
- } else {
- ncarry = valor / 10;
- valor -= (ncarry * 10);
- numero1 = valor + numero1;
- }
- } else {
- if (j == 0) {
- numero1 = valor + numero1;
- } else {
- numero1 = valor + numero1;
- }
- }
- if (contadorUnidades >= 1) {
- for (int z = 0; z < contadorUnidades; z++) {
- numero1 += '0';
- }
- }
- } else {
- if (carry) {
- valor = ((n2.charAt(i) - 48) * (n1.charAt(j) - 48) + ncarry);
- carry = false;
- }
- if (valor > 9) {
- carry = true;
- if (j == 0) {
- numero2 = valor + numero2;
- } else {
- ncarry = valor / 10;
- valor -= (ncarry * 10);
- numero2 = valor + numero2;
- }
- } else {
- if (j == 0) {
- numero2 = valor + numero2;
- } else {
- numero2 = valor + numero2;
- }
- }
- if (contadorUnidades >= 1 && j == 0) {
- for (int z = 0; z < contadorUnidades; z++) {
- numero2 += '0';
- }
- }
- }
- }
- contadorUnidades++;
- contador++;
- carry = false;
- }
- o = new BigNumber(numero1);
- o2 = new BigNumber(numero2);
- resultado += o.add(o2);
- return new BigNumber(resultado);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement