我在一个Java编程入门课程中,我试图弄清楚如何从用户输入的Int数组中填充一个数组。我已经看过我教授的所有视频,并做了很多Google搜索,但我一直无法弄清楚。
import java.util.Scanner;
public class GradesForClass {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
System.out.println("Hello Drews, how many total grades do you want to process?");
int numberOfGrades = keyboard.nextInt();
int sum = 0;
for (int i = 0; i < numberOfGrades; i++) {
System.out.println("Please enter grade " + (i + 1) + ": ");
int userGradeNumbers = keyboard.nextInt();
sum += userGradeNumbers;
}
int storeGrades[] = new int[userGradeNumbers];
int totalScore = sum;
//int lowestScore = ;
//int highestScore = ;
double averageScore = sum / (double) numberOfGrades;
System.out.println("Total score is: " + totalScore);
//System.out.println("Lowest score is: " + lowestScore);
//System.out.println("Highest score is: " + highestScore);
System.out.println("Average score is: " + averageScore);
keyboard.close();
}
}
慕容708150
相关分类