码迷,mamicode.com
首页 > 其他好文 > 详细

HW6.1

时间:2016-08-23 16:34:44      阅读:239      评论:0      收藏:0      [点我收藏+]

标签:

技术分享

 

 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 }

 

HW6.1

标签:

原文地址:http://www.cnblogs.com/wood-python/p/5799361.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!