java输入个数不定的整数,统计出现频率最高的数字,当输入为0时结束输入
程序参考
Scanner sc=new Scanner(System.in);
int a=sc.nextInt();
int []s=new int[10];
int i,b;
for(i=0;i<10;i++)
s[i]=0;
while(a!=0) {
b=a;
while(b!=0) {
s[b%10]++;
b/=10;
}
a=sc.nextInt();
}
for(i=0;i<10;i++)
System.out.printf("%d:%d
",i,s[i]);
}
运行结果
输入
123456
123456789
1012
0
输出
0:1
1:4
2:3
3:2
4:2
5:2
6:2
7:1
8:1
9:1
下一篇:php如何实现本地页面的换页
热门标签: