嘿,所以我有这个硬件作业,我必须编写一个程序,允许用户输入学生姓名和成绩,并返回最高最低和平均水平。唯一的问题是类最多有 50 名学生(或者表格上说的),而且上面只有 10 个学生的名字和成绩。我如何让数组在最后一个学生之后结束?
static final int MAX = 50;
public static void main(String[] args)
{
int index, average;
int highest = 0, student = 1;
Scanner keyboard = new Scanner(System.in);
String [] students = new String[MAX];
int[] grades = new int[MAX];
System.out.println("Please enter the name of the student and their test grade");
System.out.print("Students: ");
for(index=0; index<MAX; index++)
{
students[index] = keyboard.nextLine();
student = student + index;
if(students[index]=="Done"))
{
student = student - 1;
continue;
}
}
System.out.print("Grades: ");
for(index=0; index<student; index++)
grades[index] = keyboard.nextInt();
averageMan(grades, student);
for(index=0; index<student; index++)
if(grades[index] < averageMan(grades, student))
System.out.println(students[index] + " Your test grade was " +
"below the class average. Step it up.");
for(index=0; index<student; index++)
if(grades[index] > highest)
highest = grades[index];
System.out.println("The highest test grade in the class goes to " +
students[highest] + " with a grade of " + grades[highest]);
}
public static int averageMan(int[] g, int s)
{
int index, sum = 0;
int averages;
for(index=0; index<s; index++)
sum = sum + g[index];
averages = sum / s;
return averages;
}
最佳答案
关于java - 我如何让这个数组结束?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5912708/