HW4.9

 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 }
时间: 2024-11-05 18:54:51

HW4.9的相关文章

Stats 102A HW4

Stats 102A HW4 Due March 3, 2020General Notes• You will submit a minimum of three files, the core files must conform to the followingnaming conventions (including capitalization and underscores). 123456789 is a placeholder,please replace these nine d

HW4.30

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 balance amount: "); 10 double balance = input.nextDouble(); 11 Syste

HW4.28

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 year: "); 10 int year = input.nextInt(); 11 System.out.print("E

HW4.1

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 an int value, the program exits if the input is 0: "); 10 int inputValue

HW4.3

1 public class Solution 2 { 3 public static void main(String[] args) 4 { 5 final double POUND_PER_KILOGRAM = 2.2; 6 7 System.out.println("KILOGRAM" + "\t" + "POUND"); 8 for(int i = 1; i < 200; i += 2) 9 System.out.println(

HW4.32

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 System.out.print("Enter your lottery pick (two digits): "); 9 int guess = input.nextInt(); 10 11 i

HW4.31

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 balance: "); 10 double balance = input.nextDouble(); 11 System.out.p

HW4.19

1 public class Solution 2 { 3 public static void main(String[] args) 4 { 5 for(int i = 1; i <= 8; i++) 6 { 7 for(int j = 8 - i; j > 0; j--) 8 System.out.print(" "); 9 for(int j = 1; j <= i; j++) 10 System.out.print((int)(Math.pow(2, j -

HW4.6

1 public class Solution 2 { 3 public static void main(String[] args) 4 { 5 final double MILES_PER_KILOGRAM = 1.609; 6 7 System.out.println("Miles" + "\t" + "Kilograms" + "\t" + "Kilograms" + "\t"

HW4.2

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 int correctCount = 0; 9 int answer = 0; 10 int number1; 11 int number2; 12 13 long startTime = System.c