Menu
support@authoritypapers.com
+1(805) 568 7317

example of addition is given how do i implement subtraction thank you public class m 5188011

Example of addition is given how do i implement subtraction?

Thank you,

public class Main {

public static void main(String[] args) {

BigInt a = new BigInt(“99”);

BigInt b = new BigInt(“9”);

System.out.println(a + ” + ” + b + ” = ” + a.add(b));

System.out.println(a + ” – ” + b + ” = ” + a.sub(b));

  

}

}

class BigInt {

public BigInt() {

n = new int[1];

}

public BigInt(String s) {

n = new int[s.length()];

for (int i = 0; i

n[n.length – i – 1] = s.charAt(i) – '0';

}

}

private BigInt(int[] n) {

this.n = new int[n.length];

for (int i = 0; i

this.n[i] = n[i];

}

}

public BigInt add(BigInt o) {

int carry = 0;

int max = n.length > o.n.length ? n.length : o.n.length;

int[] result = new int[max+1];

for (int i = 0; i

int top = i

int bot = i

result[i] = (top + bot + carry) % 10;

carry = (top + bot + carry) / 10;

}

return new BigInt(trim(result));

}

public BigInt sub(BigInt o) {

return null;

}

public String toString() {

String s = “”;

for (int i : n) {

s = i + s;

}

return s;

}

private int[] trim(int[] nums) {

int size = nums.length;

for (int i = nums.length – 1; i > 0; –i) {

if (nums[i] != 0) {

break;

}

–size;

}

int[] res = new int[size];

for (int i = 0; i

res[i] = nums[i];

}

return res;

}

private int[] n;

}

"Order a similar paper and get 15% discount on your first order with us
Use the following coupon
"GET15"

Order Now