I try using BigInteger like this (where m and n are integers):
m.substract(BigInteger.ONE), n.substract(BigInteger.ONE)
it says: "cannot invoke subtract(BigInteger) on the primitive type int"
What am I doing wrong here?
I try using BigInteger like this (where m and n are integers):
m.substract(BigInteger.ONE), n.substract(BigInteger.ONE)
it says: "cannot invoke subtract(BigInteger) on the primitive type int"
What am I doing wrong here?
int
is a native datatype, it is not an object!!!
Maybe you should declare m
and n
as BigIntegers
instead?
m.substract(BigInteger.ONE) 这里的 m 只是一个int
它既不是 aBigInteger
也不是Object
任何类型的 an,而是一个原语。如果你想调用一个方法(substract(BigInteger i)
),那么 m 和 n 需要是实际拥有该方法Object
的一些。class
substract(BigInteger i)
你可以这样做:
BigInteger mBig = new BigInteger(m); // in this case n is a String
mBig = mBig.subtract(BigInteger.ONE);
顺便说一句:它被称为减法而不是减法(没有 s)
int
s 是原始时代,他们没有方法。
盒装类型,Integer
也没有subract(BigInteger)
方法。
您需要将int
s 变为BigInteger
s withBigInteger.valueOf
或将BigInteger
s 变为int
s with intValue
。
后一种方法是不安全的,因为BigInteger
可能大于Integer.MAX_VALUE
。
所以你需要做
BigInteger.valueOf(m).subtract(BigInteger.ONE),
BigInteger.valueOf(n).subtract(BigInteger.ONE)
但这有点混乱,所以为什么不这样做
BigInteger.valueOf(m - 1), BigInteger.valueOf(n - 1)