第七章練習題4

Duanhaifeng55發表於2018-04-08
public static void puppet() {
int[] nums = new int[10];
int[] count = new int[4];
Scanner input = new Scanner(System.in);
System.out.println("請輸入10個數:");
for (int i = 0; i < nums.length; i++) {
nums[i] = input.nextInt();
switch (nums[i]) {
case 1:
count[0]++;
break;
case 2:
count[1]++;
break;
case 3:
count[2]++;
break;
default:
count[3]++;
}
}
System.out.println("數字1的個數:"+count[0]);
System.out.println("數字2的個數:"+count[1]);
System.out.println("數字3的個數:"+count[2]);
System.out.println("非法數字的個數:"+count[3]);

}