标签:
1 import java.util.Scanner; 2 3 public class Solution 4 { 5 public static void main(String[] args) 6 { 7 Scanner input = new Scanner(System.in); 8 9 System.out.print("Enter the number of students: "); 10 int numberOfStudents = input.nextInt(); 11 12 System.out.print("Enter " + numberOfStudents + " scores: "); 13 int[] score = new int[numberOfStudents]; 14 int best = 0; 15 for(int i = 0 ; i < numberOfStudents; i++) 16 { 17 score[i] = input.nextInt(); 18 if(score[i] >= best) 19 best = score[i]; 20 } 21 22 input.close(); 23 24 for(int i = 0 ; i < numberOfStudents; i++) 25 System.out.println("Student " + i + " score is " + score[i] + " and grade is " + getGrade(score[i], best)); 26 } 27 28 public static char getGrade(int score, int max) 29 { 30 if(score >= max - 10) 31 return ‘A‘; 32 else if(score >= max - 20) 33 return ‘B‘; 34 else if(score >= max - 30) 35 return ‘C‘; 36 else if(score >= max - 40) 37 return ‘D‘; 38 else 39 return ‘F‘; 40 } 41 }
标签:
原文地址:http://www.cnblogs.com/wood-python/p/5799361.html