62,621
社区成员
发帖
与我相关
我的任务
分享import java.util.Scanner;
public class StudentResultEnquiry {
final int STUDENT_NUM = 6;
final int COURSE_NUM = 5;
public static void main(String[] args) {
// TODO Auto-generated method stub
String[] students = { "zhang", "wang", "li", "zhao", "liu", "song" };
String[] courses = { "C", "Java", "mySQL", "Linux", "HTML" };
int[][] scores = new int[][] { { 26, 69, 46, 25, 5 }, { 27, 10, 24, 66, 58 }, { 44, 58, 0, 82, 75 },
{ 6, 68, 92, 9, 84 }, { 75, 1, 51, 41, 74 }, { 23, 38, 65, 1, 55 } };
show(students, courses, scores);
run(students, courses, scores);
}
public static void show(String[] students, String[] courses, int[][] scores) {
System.out.print("\t");
for (int i = 0; i < courses.length; i++) {
System.out.print(courses[i] + "\t");
}
System.out.println();
for (int i = 0; i < students.length; i++) {
System.out.print(students[i] + "\t");
for (int j = 0; j < scores[i].length; j++) {
System.out.print(scores[i][j] + "\t");
}
System.out.println();
}
}
public static void run(String[] students, String[] courses, int[][] scores) {
System.out.print("请输入命令:");
Scanner scn = new Scanner(System.in);
String command = scn.next();
if (command.equalsIgnoreCase("avg")) {
String parameter = scn.next();
avg(students, courses, scores, parameter);
}
}
public static void avg(String[] students, String[] courses, int[][] scores, String condition) {
int i;
int total = 0;
for (i = 0; i < courses.length && condition!=courses[i]; i++)
System.out.println(i);
// if (i < courses.length) {
// for (int j = 0; j < students.length; j++) {
// total += scores[j][i];
// }
// System.out.printf("%s的平均分是:%.1f\n", condition, (float) (total / students.length));
// }
// for (int i = 0; i < students.length; i++)
// if (condition.equals(students[i])) {
// for (int j = 0; j < courses.length; j++) {
// total += scores[i][j];
// }
// System.out.printf("%s的平均分是:%.1f\n", condition, (float) (total / courses.length));
// }
}
}
