package homework; import java.util.Scanner; public class LegalStatistics { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("合法数字统计,1 ~ 3为合法数字,其它为非法数字"); int numArr[] = new int[10]; for (int i = 0; i < numArr.length; i++) { System.out.print("请输入第 " + (i + 1) + " 个数:"); numArr[i] = sc.nextInt(); } int num_1 = 0, num_2 = 0, num_3 = 0, others = 0; for (int i = 0; i < numArr.length; i++) { if (numArr[i] == 1) { num_1++; } else if (numArr[i] == 2) { num_2++; } else if (numArr[i] == 3) { num_3++; } else { others++; } } System.out.println("\n数字 1 出现的次数:" + num_1); System.out.println("数字 2 出现的次数:" + num_2); System.out.println("数字 3 出现的次数:" + num_3); System.out.println("非法数字出现的次数:" + others); sc.close(); } }