455,806 Members | 1,380 Online
Need help? Post your question and get tips & solutions from a community of 455,806 IT Pros & Developers. It's quick & easy.

# for loop problem

 P: 5 method "adding" don't work why??? i think this is in for loop....help me!! public class Hugeinteger{ private int[] hugeint; private int longe; private int[] result; private boolean comparison; public Hugeinteger(int[] num) { // initialise instance variables comparison = false; hugeint = new int[40]; int j = num.length-1; for(int i=39;i<=hugeint.length-num.length;i--){ hugeint[i] = num[j]; j--; } for(int k=39-num.length;k>=0;k--){ hugeint[k]=0; } longe = hugeint.length-num.length; } public Hugeinteger adding(Hugeinteger r){ //Hugeinteger result = new Hugeinteger(); result = new int[40]; int e=0; if(this.hugeint[this.longe]<0 && r.hugeint[r.longe]<0){ this.hugeint[this.longe]*=-1; r.hugeint[r.longe]*=-1; e=1; } if(this.hugeint[this.longe]<0 || r.hugeint[r.longe]<0){ subtract(r); } for(int i=39;i>=0;i--){ result[i] = this.hugeint[i]+ r.hugeint[i]; if(result[i]>9){ result[i]= result[i]-10; hugeint[i-1]+=1; } else{ result[i] = this.hugeint[i]+ r.hugeint[i]; } } if(e==1){ result[longe]*=-1; } return new Hugeinteger(result); } Apr 6 '12 #1