By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,806 Members | 1,380 Online
Bytes IT Community
+ Ask a Question
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
Share this Question
Share on Google+
2 Replies


P: 8
Hello, I think this might be the reason why:
Expand|Select|Wrap|Line Numbers
  1. public Hugeinteger adding(Hugeinteger r){
  2. //Hugeinteger result = new Hugeinteger();
  3.  
It looks like you have "//" comment marks in the middle of your function statements...?
Apr 6 '12 #2

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

thank you!
Apr 6 '12 #3

Post your reply

Sign in to post your reply or Sign up for a free account.