如果有人愿意给我一个这个程序的手,它将不胜感激,它接受多个学生的姓名和成绩使用扫描仪,然后将它们放入2个数组,学生和分数。然后它会打印出如下...Java扫描器输入到int和字符串数组
最大。等级= 98(劳伦)
最小。等级= 50(Joe)
平均等级= 83.9
/* Chris Brocato
* 10-27-15
* This program will read the students names and scores using a Scanner and use two arrays to
* show the grade and name of the highest and lowest scoring student as well as the average grade.*/
import java.util.*;
public class StudentCenter {
public static void main(String[] args) {
Scanner console = new Scanner(System.in);
System.out.print("Please enter the number of students: ");
int students = console.nextInt();
String[] name = new String[students];
int[] scores = new int[students];
int min = 0; int max = 0; int sum = 0;
for (int i = 0; i < name.length; i++) {
System.out.print("Please enter student's name: ");
name[i] = console.next();
System.out.print("Now enter their score: ");
scores[i] = console.nextInt();
if (i == 0) {
min = students;
max = students;
}else {
if (students < min) min = students;
if (students > max) max = students;
}sum += students;
}
System.out.println("Min. Grade = " + min + name);
System.out.println("Max. Grade = " + max + name);
System.out.println("Average Grade = " + sum);
double avg = (double) sum/(double) students;
System.out.println("Avg = " + avg);
console.close();
}
}
这不是问题。你有什么特别的问题? –
对不起,我没有得到正确的输出,最小和最大都给出了相同的数字,我认为它只是最后输入的数字,但我不明白为什么。 –