- package DigitCounter;
- public class DigitCounter {
- /**
- * @param args
- */
- public static void main(String[] args) {
- int [] count = new int[10];
- for(int i = 0;i < 100 ; i++){
- int num = (int)(Math.random()*10);
- System.out.print(num);
- switch (num) {
- case 0:
- count[0] +=1;
- break;
- case 1:
- count[1] +=1;
- break;
- case 2:
- count[2] +=1;
- break;
- case 3:
- count[3] +=1;
- break;
- case 4:
- count[4] +=1;
- break;
- case 5:
- count[5] +=1;
- break;
- case 6:
- count[6] +=1;
- break;
- case 7:
- count[7] +=1;
- break;
- case 8:
- count[8] +=1;
- break;
- case 9:
- count[9] +=1;
- break;
- }
- }
- System.out.println();
- for(int i = 0; i<count.length ; i ++){
- System.out.println("有"+count[i]+"个"+i);
- }
- }
- }
复制代码
求分,楼主如果感觉有什么问题,随时指出,立即更改 谢谢 |