망나니 AWOS의 일상
article thumbnail

import java.math.BigInteger;
import java.util.Scanner;

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));
    }


}

int는 메모리 크기는 4byte로 표현할 수 있는 범위는 -2,147,483,648 ~ 2,147,483,647 이고

long은 메모리 크기는 8byte로 표현할 수 있는 범위는 -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807 이다.

 

하지만 그 범위를 넘어서게 되면 모두 0으로 출력이 된다.

 

숫자의 범위가 무한한 BigInteger란 클래스를 쓰면 쉽게 풀 수 있다.

 

 

profile

망나니 AWOS의 일상

@AWOS

포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!