-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCounter.java
67 lines (62 loc) · 1.25 KB
/
Counter.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
public class Counter {
public static void main(String[] args) {
// TODO Auto-generated method stub
int count0 = 0;
int count1 = 0;
int count2 = 0;
int count3 = 0;
int count4 = 0;
int count5 = 0;
int count6 = 0;
int count7 = 0;
int count8 = 0;
int count9 = 0;
long a1 = 12345679890l;
while(a1 > 0) {
int x = (int) (a1 % 10);
switch(x) {
case 0:
count0++;
break;
case 1:
count1++;
break;
case 2:
count2++;
break;
case 3:
count3++;
break;
case 4:
count4++;
break;
case 5:
count5++;
break;
case 6:
count6++;
break;
case 7:
count7++;
break;
case 8:
count8++;
break;
case 9:
count9++;
break;
}
a1 /= 10;
}
System.out.println("count0 = " + count0);
System.out.println("count1 = " + count1);
System.out.println("count2 = " + count2);
System.out.println("count3 = " + count3);
System.out.println("count4 = " + count4);
System.out.println("count5 = " + count5);
System.out.println("count6 = " + count6);
System.out.println("count7 = " + count7);
System.out.println("count8 = " + count8);
System.out.println("count9 = " + count9);
}
}