我玩弄java.math.BigInteger。這是我的java類,java.math.BigInteger的用法是否錯誤?
public class BigIntegerTest{
public static void main(String[] args) {
BigInteger fiveThousand = new BigInteger("5000");
BigInteger fiftyThousand = new BigInteger("50000");
BigInteger fiveHundredThousand = new BigInteger("500000");
BigInteger total = BigInteger.ZERO;
total.add(fiveThousand);
total.add(fiftyThousand);
total.add(fiveHundredThousand);
System.out.println(total);
}
}
我認爲結果是555000
。但實際是0
。爲什麼?
+1使用'long'是* *很多簡單的,當然。 –
@PeterLawrey當然,如果你知道你的值只需要63位;-) – Alnitak