问题是什么??
用这种方式发代码, 可以更快地帮你调试:
https://lightly.teamcode.com/dashboard
发个链接给你,java,c,c++,py 都可以用的,不用下载安装包
简单写了下:
public class StudentAndScore {
public static void main(String[] args) {
int num = 10;
String[] students = new String[num];
double[] scores = new double[num];
for (; ; ) {
int ch = getMenu();
if (ch == 0) {
break;
}
if (ch == 1) {
inputScore(students, scores);
}
if (ch == 2) {
findScore(students, scores);
}
if (ch == 3) {
changeScore(students, scores);
}
if (ch == 4) {
doAvg(scores);
}
if (ch == 5) {
doSort(students, scores);
}
if (ch == 6) {
show(students, scores);
}
if (ch == 8) {
students = addStudents(students);
scores = addScores(students[students.length - 1], scores);
}
}
}
private static double[] addScores(String student, double[] scores) {
return null;
}
private static String[] addStudents(String[] students) {
return null;
}
private static void show(String[] students, double[] scores) {
for (int i = 0; i < students.length; i++) {
System.out.println("学生:" + students[i] + ",成绩为:" + scores[i]);
}
}
private static void doSort(String[] students, double[] scores) {
Arrays.sort(scores);
for (int i = scores.length - 1; i >= 0; i--) {
System.out.println("成绩为:" + scores[i]);
}
}
private static void doAvg(double[] scores) {
double total = 0.0;
for (double score : scores) {
total += score;
}
System.out.println("平均分为:" + total / scores.length);
}
private static void changeScore(String[] students, double[] scores) {
Arrays.sort(scores);
for (int i = scores.length - 1; i >= 0; i--) {
System.out.println("成绩为:" + scores[i]);
}
}
private static void findScore(String[] students, double[] scores) {
for (int i = 0; i < students.length; i++) {
System.out.println("学生:" + students[i] + ",成绩为:" + scores[i]);
}
}
private static void inputScore(String[] students, double[] scores) {
for (int i = 0; i < students.length; i++) {
students[i] = getRandomName(6);// 假设学生姓名长度为0
scores[i] = new Random(100).nextDouble();
}
}
private static int getMenu() {
return new Random().nextInt(6);
}
private static String getRandomName(int length) {
return UUID.randomUUID().toString().substring(0, length);
}
}