ZZULIOJ 1151: Large Integer Addition, Java

ZZULIOJ 1151: Large Integer Addition, Java

Question description

Billy often encounters the addition of very large integers, which cannot be performed on an ordinary calculator. So he wants you to help him write a program to calculate the result.

enter

There are multiple sets of input data. First, enter an integer T, indicating that there are T groups of inputs.

Enter two large integers in each group, separated by spaces. Each integer can have up to 1000 digits. No negative numbers are entered.

output

For each set of inputs, output the sum of two integers on a separate line.

Sample inputCopy
2
1 2
112233445566778899 998877665544332211
Sample outputCopy
3
1111111111111111110
import java.io.*;
import java.math.BigInteger;

public class Main {
    
    
    public static void main(String[] args) throws IOException {
    
    
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        int T = Integer.parseInt(bf.readLine());
        while (T-- > 0) {
    
    
            String[] str = bf.readLine().split(" ");
            BigInteger a = new BigInteger(str[0]);
            BigInteger b = new BigInteger(str[1]);
            bw.write(a.add(b) + "\n");
        }
        bw.close();
    }
}

Guess you like

Origin blog.csdn.net/qq_52792570/article/details/132568914