for loop problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • zahra abaszade
    New Member
    • Apr 2012
    • 5

    for loop problem

    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(Hugeinte ger 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(res ult);
    }
  • codechick
    New Member
    • Feb 2012
    • 8

    #2
    Hello, I think this might be the reason why:
    Code:
    public Hugeinteger adding(Hugeinteger r){
    //Hugeinteger result = new Hugeinteger();
    It looks like you have "//" comment marks in the middle of your function statements...?

    Comment

    • zahra abaszade
      New Member
      • Apr 2012
      • 5

      #3
      no!! problem was in for loop i should write...
      for(int i=39;i>=hugeint .length-num.length;i--)

      thank you!

      Comment

      Working...