import java.util.Random;
//求每个数字出现的次数、出现次数最多的数、出现最大次数的值的数字
public class RandomTest2 {
public static void main(String[] args) {
int[] count = new int[41];
Random random = new Random();//产生随机数
for(int i=0;i<50;i++){
int number = random.nextInt(41)+10;//产生随机数[10,50]
System.out.println(number);
count[number-10]++;//保存次数
}
//每个数字出现的次数
for(int j=0;j<count.length;j++){
if(0==count[j]){//如果没有出现该数字
continue;
}
System.out.println((j+10)+"出现的次数是:"+count[j]);//每个数字出现的次数
}
//出现的最大次数
int max = count[0];//假设第一个数是最大的
for(int k=0;k<count.length;k++){
if(max<count[k]){
max = count[k];
}
}
System.out.println("出现的最大次数是:"+max+"次");
//出现最大次数的值的数字
for(int m=0;m<count.length;m++){
if(max==count[m]){
System.out.println("出现最大的次数的值是"+(m+10));//出现最大的次数的值是m+10
}
}
}
}