HW6.1

时间:2022-10-13 17:43:39

HW6.1

 import java.util.Scanner;

 public class Solution
 {
     public static void main(String[] args)
     {
         Scanner input = new Scanner(System.in);

         System.out.print("Enter the number of students: ");
         int numberOfStudents = input.nextInt();

         System.out.print("Enter " + numberOfStudents + " scores: ");
         int[] score = new int[numberOfStudents];
         int best = 0;
         for(int i = 0 ; i < numberOfStudents; i++)
         {
             score[i] = input.nextInt();
             if(score[i] >= best)
                 best = score[i];
         }

         input.close();

         for(int i = 0 ; i < numberOfStudents; i++)
             System.out.println("Student " + i + " score is " + score[i] + " and grade is " + getGrade(score[i], best));
     }

     public static char getGrade(int score, int max)
     {
         if(score >= max - 10)
             return 'A';
         else if(score >= max - 20)
             return 'B';
         else if(score >= max - 30)
             return 'C';
         else if(score >= max - 40)
             return 'D';
         else
             return 'F';
     }
 }

相关文章