基本上,我需要获得5个等级的用户输入,将它们加在一起并获得平均值.在获得平均值之前,我还需要以某种方式从该数组中删除最低值.
最重要的是,我需要以某种方式循环所有这些,以便它在结束时询问"如果你想重做这个东西,键入true,如果你完成了就输入false"但我想知道如何首先删除最低值
顺便说一下,我还没有"正式"学会如何做数组或循环,所以所有这些都没有意义是自学.
import java.util.Scanner;
import java.util.Arrays;
class calculateGrades{
public static void main(String args[]){
int[] grades=new int[5]; //Array for assignment grades
int sum=0;
int average;
Scanner keyboard=new Scanner(System.in);
//This loop is to take in the user input for assignment grade
System.out.println("please enter your 5 assignment grades: ");
for (int fcount=0;fcount<grades.length;fcount++){
grades[fcount]=keyboard.nextInt();
}
//After this loop is done, all the grades are now placed in the
//grades array.
//Find the minimum value in the array.
Arrays.sort(grades);
int mn = grades[0];
//This loop is to calculate the sum of the inputed array.
for(int counter=0;counter<grades.length;counter++){
sum=sum+grades[counter];
}
//Now that this array calculated the sum of the array we find the average
average = (sum - mn) /4;
System.out.println(average);
System.out.println(mn);
}
}
}
Run Code Online (Sandbox Code Playgroud)
所以有人可以帮助我吗?
我不会将其从数组中删除,而是跟踪最小值,然后从总和中减去它.
如果您无法跟踪最小值,请告诉我.