投票统计的数组用法

来源:互联网 发布:linux nginx开机启动 编辑:程序博客网 时间:2024/06/06 01:17
package welcome;


import java.util.Scanner;


public class 投票统计 {


public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
int x;
x = in.nextInt();
int [] a= new int[10];
while(x != -1)
{
if(x >= 0 && x <= 9)
{
a[x]++;
}
x = in.nextInt();
}
for(int i = 0; i < 10; i++)
{
System.out.println(a[i]);
}
}


}