백준 13277번 www.acmicpc.net/problem/13277

 

 

 

풀이

 

큰 수의 곱셈을 할 때에는 java.math에 있는 BigDecimal 타입을 사용해서 계산한다. 스캐너로 받을 때도 .nextBigInteger(); 와 같이 해주면 되고, 사칙연산은 연산자가 아닌 내장 메서드를 통해 .multiply() 로 계산한다.

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
import java.math.*;
import java.util.*;
 
public class codinginteview_13277 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        BigInteger a = sc.nextBigInteger();
        BigInteger b = sc.nextBigInteger();
        sc.nextLine();
        
        System.out.println(a.multiply(b));
        sc.close(); 
    }
}
cs
댓글