variable.equals(variable.add(new BigInteger ("1")));
equals
方法从某种意义上告诉您两个对象是否“等效”,因此它类似于==
运算符。您要查找的是assignment运算符。没有办法,只需使用=
。
BigInteger.ONE
。variable = variable.add(BigInteger.ONE);
String
和Integer
,BigInteger
是不可输入的。 add
方法不会更改variable
,而是返回具有更改后的值的新BigInteger
。您的equals
始终为假
所以您要做的是
variable = variable.add(new BigInteger("1"));
将更改变量。在相关说明上,请勿使用
.equals
比较两个BigIntegers
和variable.compareTo(other) == 0