作为补充,如果64位长不符合您的要求,请尝试java.math.BigInteger 。
适用于超过64位长度范围的情况。
public static void main(String args[]){ String max_long = "9223372036854775807"; String min_long = "-9223372036854775808"; BigInteger b1 = new BigInteger(max_long); BigInteger b2 = new BigInteger(min_long); BigInteger sum = b1.add(b1); BigInteger difference = b2.subtract(b1); BigInteger product = b1.multiply(b2); BigInteger quotient = b1.divide(b1); System.out.println("The sum is: " + sum); System.out.println("The difference is: " + difference); System.out.println("The product is: " + product); System.out.println("The quotient is: " + quotient); }
输出是:
总数是:18446744073709551614
区别在于:-18446744073709551615
该产品是:-85070591730234615856620279821087277056
商是:1