import java.util.Arrays;
public class CountingHighestNumber {
public static void main(String args[]) {
int count = 0;
String str = "2 3 4 3 8 8 3 5 2 6 8";
String[] strArray = str.trim().split(" ");
int size = strArray.length;
int[] intArray = new int[size];
for(int i = 0; i<size; i++) {
intArray[i] = Integer.parseInt(strArray[i]);
}
System.out.println("Integer Array ::"+Arrays.toString(intArray));
Arrays.sort(intArray);
System.out.println("sorted Array ::"+Arrays.toString(intArray));
int max = intArray[size-1];
System.out.println("Max value is :"+max);
for(int i = 0; i<size; i++) {
if(intArray[i]==max) {
count++;
}
}
System.out.println("Number of times the largest value repeated is ::"+count);
}
}
输出
Integer Array ::[2, 3, 4, 3, 8, 8, 3, 5, 2, 6, 8]
sorted Array ::[2, 2, 3, 3, 3, 4, 5, 6, 8, 8, 8]
Max value is :8
Number of times the largest value repeated is ::3