해설
기본적인 사칙연산만 하다가 조금 복잡한 연산이 나왔습니다.
숫자 A가 주어졌을 때 숫자 B를 곱하는 방법은 다음과 같습니다.
각 자리수를 곱해주어야하기 때문에 굳이 숫자 B는 int로 받지않았습니다. String으로 받아서 각 자리를 char로 반복하면 각 자리를 손쉽게 얻을 수 있습니다. char의 경우, 유니코드 값이 존재하므로 '0'을 빼준다면 문자가 가지는 실제 숫자를 얻을 수 있습니다.
코드
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int A = Integer.parseInt(br.readLine());
String B = br.readLine();
int sum = 0; // 합
int digit = 1; // 자리수
for (int i = B.length()-1; i >= 0; i--) {
System.out.println(A * (B.charAt(i) - '0'));
sum += A * (B.charAt(i) - '0') * digit;
digit *= 10;
}
System.out.println(sum);
}
}