java做大数加法

java做大数加法

java做大数运算的类是BigInteger

import java.util.Scanner;
import java.math.BigInteger;
 
public class Main {
    public static void main(String[] args) {
        BigInteger a,b,c;
        int n;
        Scanner cin = new Scanner(System.in);
        n = cin.nextInt();
        for(int i=1;i<=n;i++)
        {
        a = cin.nextBigInteger();
        b = cin.nextBigInteger();
        c = a.add(b);
        System.out.println("Case " + i + ":");
        System.out.println(a + " + " + b + " = " + c);
        if(i!=n)
            System.out.println();
        }
    }
}

猜你喜欢

转载自blog.csdn.net/qq_39905917/article/details/84303407
今日推荐