I could use some help with an assignment. The user has to enter the number of students and then enter scores and I have to find the best score and assign a grade accordingly.
Grade is A if score is >= best-10
Grade is B if score is >= best-20
Grade is C if score is >= best-30
Grade is D if score is >= best-40
Grade is F otherwise
My program is not producing the correct grades at the moment and I tried putting another for loop right before my if but nothing changed and then I tried using another variable (j instead of i) but I'm sort of stuck. I'm new to java so any help would be appreciated, and thank you in advance :)
``````````````````````````````````````````````
import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter the number of students: ");
int students = input.nextInt();
int[] grades = new int [students];
System.out.print("Enter " + students + " scores: ");
for(int i=0; i<students; i++){
grades[i] = input.nextInt();
}
int max = grades[0];
for(int i = 0; i<grades.length; i++){
if(grades[i] > max){
max = grades[i];
}
for(i = 0; i<grades.length; i++){
if (grades [i] >= max-10){
System.out.println("Student " + i + " score is: A");
}else if (grades[i] >= max-20){
System.out.println("Student " + i + " grade is: B");
}else if (grades [i] >= max-30){
System.out.println("Student " + i + " grade is: C");
}else if (grades[i] >= max-40){
System.out.println("Student " + i + " grade is: D");
}else{
System.out.println("Student " + i + " grade is: F");
}
}
}
}
}
`````````````````````````````````````````
Aucun commentaire:
Enregistrer un commentaire