我在方法的头部有以下代码:
BigInteger foo = BigInteger.valueOf(0);
BigInteger triNum = BigInteger.valueOf(0);
//set min value to 1*2*3*4*5*...*199*200.
BigInteger min = BigInteger.ONE;
BigInteger temp = BigInteger.ZERO;
for(int i=1; i<=200; i++)
{
temp = BigInteger.valueOf(i);
min = min.multiply(temp);
}
System.out.println(min);
while(triNum.compareTo(min) <= 0)
{
foo.add(BigInteger.ONE);
triNum = triNum.add(foo);
System.out.println("triNum: "+triNum);
}
Run Code Online (Sandbox Code Playgroud)
这应该将min加载到一个值(1*2*3*...*199*200),然后将triNum设置为第一个*三角形数**,其值大于min.
问题是,当我运行该方法时,我得到的是一个终端窗口,其中"triNum:0"列表在屏幕上滚动...我的代码中没有看到任何内容(尽管我完全可以做到有些错误,我对math.BigInteger有些不熟悉,这似乎又指向了BigInteger类.有人看到我的代码中有错误吗?
.................................................. .................................................. ......................
*三角形数字是一个可以达到的数字:1 + 2 + 3 + 4 + 5 + 6 + 7 + ......
看着
foo.add(BigInteger.ONE);
Run Code Online (Sandbox Code Playgroud)
这会更新foo吗?或者它是否创建了一个等于foo+ BigInteger.ONE不再使用的对象?
| 归档时间: |
|
| 查看次数: |
781 次 |
| 最近记录: |