package ggg;
public class wda {
public double calavg(int[] scores) {
int sum = 0;
double avg = 0.0;
for (int i = 0; i < scores.length; i++) {
sum += scores[i];
}
avg = (double) sum / scores.length;
return avg;
}
public int calmax(int[] scores) {
int max = scores[0];
for (int i = 0; i < scores.length; i++) {
if (max < scores[i]) {
max = scores[i];
}
}
return max;
}
}
package ggg;
import java.util.*;
public class wda1 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
wda s = new wda();
int[] scores = new int[5];
System.out.println("输入5名参赛者的成绩:");
for (int i = 0; i < 5; i++) {
scores[i] = input.nextInt();
}
double avgscore = s.calavg(scores);
System.out.println("平均成绩:" + avgscore);
int max = s.calmax(scores);
System.out.println("最高成绩:" + max);
}
}