java表示bigint
java表示bigint在Java中,可以使用java.math.BigInteger类来表示任意大的整数。以下是一个使用BigInteger的示例代码:
import java.math.BigInteger;
public class BigIntExample {
public static void main(String[] args) {
// 创建一个BigInteger对象
BigInteger bigInteger = new BigInteger("123456789012345678901234567890");
// 打印BigInteger对象
System.out.println("BigInteger: " + bigInteger);
// 加法操作
BigInteger anotherBigInteger = new BigInteger("98765432109876543210987654321");
BigInteger sum = bigInteger.add(anotherBigInteger);
System.out.println("Sum: " + sum);
// 减法操作
BigInteger difference = bigInteger.subtract(anotherBigInteger);
System.out.println("Difference: " + difference);
// 乘法操作
BigInteger product = bigInteger.multiply(anotherBigInteger);
System.out.println("Product: " + product);
// 除法操作
BigInteger quotient = sum.divide(product);
System.out.println("Quotient: " + quotient);
}
}这段代码展示了如何创建BigInteger对象,以及如何对它们进行基本算术运算,包括加法、减法、乘法和除法。BigInteger类还提供了其他操作,如比较、模运算等。
页:
[1]