-
Notifications
You must be signed in to change notification settings - Fork 0
/
ch5.java
52 lines (50 loc) · 1.39 KB
/
ch5.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import java.util.Scanner;
public class ch5 {
public static void main(String[] args) {
System.out.print("num=");
Scanner scn = new Scanner(System.in);
long num = scn.nextLong();
scn.close();
int[] ans = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
for(int i = 12;i > 0; i--){
switch ((int)(num % 10)) {
case 0:
ans[0] += 1;
break;
case 1:
ans[1] += 1;
break;
case 2:
ans[2] += 1;
break;
case 3:
ans[3] += 1;
break;
case 4:
ans[4] += 1;
break;
case 5:
ans[5] += 1;
break;
case 6:
ans[6] += 1;
break;
case 7:
ans[7] += 1;
break;
case 8:
ans[8] += 1;
break;
case 9:
ans[9] += 1;
break;
default:
break;
}
num /= 10;
}
for(int i = 0; i < 10; i++){
System.out.println(i + "出現" + ans[i] + "次");
}
}
}