import java.util.Arrays;
public class ScoreAnalyzer {
public static void main(String[] args) {
int[] scores = {88, 92, 75, 99, 64, 72, 85, 91, 78, 80};
int maxScore = getMaxScore(scores);
int minScore = getMinScore(scores);
int[] sortedScores = bubbleSort(scores);
System.out.println("最高分:" + maxScore);
System.out.println("最低分:" + minScore);
System.out.println("按成绩高低排序:" + Arrays.toString(sortedScores));
}
public static int getMaxScore(int[] scores) {
int max = scores[0];
for (int i = 1; i < scores.length; i++) {
if (scores[i] > max) {
max = scores[i];
}
}
return max;
}
public static int getMinScore(int[] scores) {
int min = scores[0];
for (int i = 1; i < scores.length; i++) {
if (scores[i] < min) {
min = scores[i];
}
}
return min;
}
public static int[] bubbleSort(int[] scores) {
int[] sortedScores = Arrays.copyOf(scores, scores.length);
for (int i = 0; i < sortedScores.length - 1; i++) {
for (int j = 0; j < sortedScores.length - i - 1; j++) {
if (sortedScores[j] < sortedScores[j + 1]) {
int temp = sortedScores[j];
sortedScores[j] = sortedScores[j + 1];
sortedScores[j + 1] = temp;
}
}
}
return sortedScores;
}
}
温馨提示:答案为网友推荐,仅供参考