日期:2014-05-20 浏览次数:20738 次
public static void main(String[] args) { Scanner scan = new Scanner(System.in); int[] ins = new int[10]; int count = 0; //循环输入10个数字 while(true){ if(count == ins.length){ break; } try { int in = scan.nextInt(); ins[count] = in; count++; } catch (RuntimeException e) { e.printStackTrace(); } } int one = 0; int two = 0; int three = 0; int other = 0; //循环查找合法数字 for(int i = 0; i < ins.length; i++){ if(ins[i] == 1){ one++; }else if(ins[i] == 2){ two++; }else if(ins[i] == 3){ three++; }else{ other++; } } System.out.println("1的个数:" + one); System.out.println("2的个数:" + two); System.out.println("3的个数:" + three); System.out.println("其他数字的个数:" + other); }
------解决方案--------------------