Question
Can someone check my huge integer add function please and the negative add? I am trying to add 99+999 but it is giving me 98
Can someone check my huge integer add function please and the negative add?
I am trying to add 99+999 but it is giving me 98 instead of 1098
public HugeInteger add(HugeInteger h) { int checkRun = this.flag; int checkRun2 = h.flag; int bigNeg=0; if(h.flag==1) { h.flag = this.flag; h.size = h.size-1; bigNeg = this.compareTo(h); this.flag = checkRun; h.flag = checkRun2; h.size+=1; } else { this.flag = h.flag; this.size = this.size-1; ///pronlem bigNeg = this.compareTo(h); this.flag = checkRun; h.flag = checkRun2; this.size+=1; } //this ensures we use the bigger of the two strings to make a new hugeInteger int newLength = 0; newLength = this.size; int smallLength = h.size; if(h.size > this.size) { newLength = h.size; smallLength = this.size; } else if(h.size == this.size) { newLength = h.size+1; smallLength = this.size+1; } //new integer HugeInteger newHuge = new HugeInteger(newLength); //check sign int run= this.compareTo(h); switch (run) { case 1: newHuge.size = this.size; break; case -1: newHuge.size = h.size; break; default: newHuge.size = (this.size+h.size)/2; break; } //hold is the sum of the two strings elemets int hold = 0; //since we create a random string we need to fix it by zeroing it otherwise it ends up adding to the hold sum for(int i = 0 ; i
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started