[Java] 백준 2588번 - 곱셈
Java 산술 연산자 나머지(%)와 몫(/) 활용, 숫자 자릿수 분리 및 단계별 곱셈 연산 원리
For the English version of this post, see here.
[Java] 백준 2588번 - 곱셈
풀이
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import java.util.Scanner;
public class Main{
public static void main(String args[]) {
Scanner input = new Scanner(System.in);
int a = input.nextInt();
int b = input.nextInt();
int c = a * (b%10);
int d = a * ((b%100)/10);
int e = a * (b/100);
int f = a * b;
System.out.printf("%d\n%d\n%d\n%d", c, d, e, f);
}
}
Java에서 / 연산자는 몫만 반환한다는 것을 이용해 계산했다.
댓글
궁금한 점, 피드백, 오류 제보를 남겨 주세요.