9.26

import java.math.BigInteger;

public class SimpleBigInteger {
public static void main(String[] args) {
// 初始化大整数(用字符串避免溢出)
BigInteger bigNum = new BigInteger("12345678901234567890");
BigInteger smallNum = BigInteger.valueOf(123);

    // 核心运算
    BigInteger sum = bigNum.add(smallNum);       // 加法
    BigInteger product = bigNum.multiply(smallNum); // 乘法
    BigInteger power = bigNum.pow(2);            // 平方(2次幂)

    // 打印结果
    System.out.println("加法:" + sum);
    System.out.println("乘法:" + product);
    System.out.println("平方:" + power);
}

}

posted @ 2025-09-26 20:24  喜欢写轻小说的日央  阅读(5)  评论(0)    收藏  举报