내가 작성한 답안
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int A = sc.nextInt();
int B = sc.nextInt();
int num = 0;
num = B % 10;
System.out.println(A*num);
num = (B/10) % 10;
System.out.println(A*num);
num = (B/100) % 10;
System.out.println(A*num);
System.out.println(A*B);
}
}
아주 원시적이다... 하하
아직은 머릿속으로 떠오르는 알고리즘을 코드로 옮기는 과정이 낯설긴 하다.
더보기
a % 10 -> 일의 자리
(a/10) % 10 -> 10의 자리
a / 100 -> a-> 100의 자리
다른 분들의 풀이를 참고하여 머릿속으로 구현하고자 했던 답안도 작성해보았다.
import java.util.Scanner;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
int answer = a*b;
for (int i = 0; i < 3 ;i ++) {
int r = b%10;
System.out.println(r*a);
b = b/10;
}
System.out.println(answer);
}
}
'Coding Test > 백준' 카테고리의 다른 글
[백준 1330번 - java] 두 수 비교하기 (0) | 2021.11.03 |
---|---|
[백준 9498번 - java] 시험 성적 (0) | 2021.11.03 |
[백준 2753번 - java] 윤년 (0) | 2021.11.03 |
[백준 2558번 - java] A+B - 2 (0) | 2021.11.02 |
[백준 1008번 - java] A/B (0) | 2021.11.02 |