把它们全部统计一下就可以了.
public static void randomstatic() {
int[] number = new int[10];
Random r = new Random();
int count = 0;//统计出现最多数字出现的次数
int many = 0;//统计出现最多的数字
for (int i = 0; i < number.length; i++) {
int temp = r.nextInt(10);
number[i] = temp;
}
for (int i = 0; i < number.length; i++) {
int count1 = 0;//临时存储当次比较数字出现的次数
for (int j = 0; j < number.length; j++) {
if (number[i] == number[j]) {
count1++;
}
if (count1 >= count) {
count=count1;
many = number[i];
}
}
}
HashMap<Integer, Integer> map = new HashMap<>();
Integer val, max = -1 , i;
for( i = 0; i < number.length; i++) {
val = map.get(number[i]);
if(val!=null) {
map.put(number[i], ++val);
if(max < val) max = val;
}
else {
map.put(number[i], 1);
}
}
Set<Integer> set = map.keySet();
String str = "输出数量最多值: ";
for(Integer s : set) {
if(map.get(s) == max) str +=
s + "
";
}
System.out.println(map);
System.out.println(str + "出现次数:: " + max);
System.out.println("输出数量最多值:"+many+"出现做多次数:"+count);
for (i = 0; i < number.length; i++) {
System.out.print(number[i] + " , ");
}
System.out.println();
}