1. Scanner 사용
- number.charAt() - '0' : char 에서 int 변환한다.(가장 간단한 방법)
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int value=(sc.nextInt() * sc.nextInt() * sc.nextInt());
String number = Integer.toString(value);
for(int i=0; i<10; i++) {
int count=0;
for(int j=0; j<number.length(); j++) {
if((number.charAt(j) - '0')==i) {
count ++;
}
}
System.out.println(count);
}
}
}
2. BufferedReader 사용
- str.charAt() - '0' or str.charAt() - 48 으로 정수 변환
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int[] num = new int[10];
int value = Integer.parseInt(br.readLine()) * Integer.parseInt(br.readLine()) * Integer.parseInt(br.readLine());
String str = String.valueOf(value);
for(int i=0; i<str.length(); i++) {
num[(str.charAt(i) - '0')]++;
}
for(int v : num) {
System.out.println(v);
}
}
}
'Study > [Algorithm]' 카테고리의 다른 글
[백준] 2941번 - 크로아티아 알파벳 (0) | 2021.05.29 |
---|---|
[백준] 1929번 - 소수 구하기 (0) | 2021.05.28 |
[백준] 1152번 JAVA - 단어의 개수 (0) | 2021.05.27 |
[백준] 1110번 JAVA - 더하기 사이클 (0) | 2021.05.20 |
[백준] 10951번 JAVA - EOF(End Of File) (0) | 2021.05.20 |
댓글