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

HW4.9

时间:2016-08-14 13:12:13      阅读:129      评论: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         int score = 0;
13         int max = 0;
14         int secondMax = 0;
15         String student = "";
16         String maxStudent = "";
17         String secondMaxStudent = "";
18 
19         for(int i = 0; i < numberOfStudents; i++)
20         {
21             System.out.print("Enter a student‘s name: ");
22             student = input.next();
23 
24             System.out.print("Enter his score: ");
25             score = input.nextInt();
26 
27             if(score > max)
28             {
29                 secondMax = max;
30                 secondMaxStudent = maxStudent;
31                 max = score;
32                 maxStudent = student;
33 
34             }
35         }
36 
37         input.close();
38 
39         System.out.println("The one has best score is " + maxStudent + ", his score is " + max);
40         System.out.println("The one has second score is " + secondMaxStudent + ", his score is " + secondMax);
41     }
42 }

 

HW4.9

标签:

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

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