【发布时间】:2013-10-05 21:32:09
【问题描述】:
这是我的代码的一部分。在带有 for 循环的部分: 我一生都无法弄清楚为什么它只循环一次。我已经盯着这个看了好几个小时,想知道为什么它只做一次。 parse 等于 3,所以如果我的逻辑正确,它应该执行 3 次。谢谢。
public BigInt multiplcationHelper(BigInt B1,BigInt B2) {
int size1 = this.num.size(), size2 = B2.num.size();// sizes of B1 and B2
BigInt result = new BigInt();
int parse = Integer.parseInt(B2.toString());
int farse = Integer.parseInt(B1.toString());
// result's num initial capacity of one more than B1's num and fill with null objects.
result.num = new ArrayList (Collections.nCopies( size1+1, null ));
//Both B1 and B2 are positive
//if (B1.isPositive && B2.isPositive){
for (int i = 0; i<parse; i++) {
B1.add(B1);
//}
}
//result = B1;
return B1;
}
【问题讨论】:
-
您应该打印出
parse的值以确定,或者在调试器中单步执行。 -
因为
BigInt是您自己的实现,发布代码只是为了确保您的方法add和toString中没有任何内容
标签: java loops for-loop integer