문법/알게된 메소드

long을 벗어나는 큰 수 다룰 때

코딩 화이팅 2023. 2. 8. 22:39

https://coding-factory.tistory.com/604

 

[Java] 큰 숫자(정수) 다루기 BigInteger 사용법 & 예제 총정리

BigInteger를 사용해야 하는 이유 Type 범위 int -2,147,483,648 ~ 2,147,483,647 long -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807 int는 메모리 크기는 4byte로 표현할 수 있는 범위는 -2,147,483,648 ~ 2,147,483,647이고 long

coding-factory.tistory.com

package 기본수학1;

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

public class bj10757 {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		
		BigInteger A=new BigInteger(sc.next());//값을 입력받을 때
		BigInteger B=new BigInteger(sc.next());
		
		A=A.add(B);
		
		System.out.println(A.toString());//출력할 때
	}
}