
두 정수 A와 B를 입력받은 다음, A+B를 출력하는 프로그램을 작성하시오.
첫째 줄에 A와 B가 주어진다. (0 < A,B < )
첫째 줄에 A+B를 출력한다.
자바에는 BigInteger 타입이 존재하여 이를 이용하면 손쉽게 구할 수 있다. 자세한 것은 자바 API를 보자. (링크)
BigInteger must support values in the range -2^Integer.MAX_VALUE (exclusive) to +2^Integer.MAX_VALUE (exclusive) and may support values outside of that range. The range of probable prime values is limited and may be less than the full supported positive range of BigInteger. The range must be at least 1 to .
A와 B의 범위가 (0 < A,B < )이기 때문에 충분히 BigInteger를 사용 할 수 있다.
다른 방법으로는 1차원 배열을 만들어 각 자리의 수를 합하여 저장하는 방식으로 해결할 수 있다.
import java.math.*;
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
BigInteger a = sc.nextBigInteger();
BigInteger b = sc.nextBigInteger();
System.out.println(a.add(b));
}
}