如果有人願意給我一個這個程序的手,它將不勝感激,它接受多個學生的姓名和成績使用掃描儀,然後將它們放入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();
}
}
這不是問題。你有什麼特別的問題? –
對不起,我沒有得到正確的輸出,最小和最大都給出了相同的數字,我認爲它只是最後輸入的數字,但我不明白爲什麼。 –