@GetMapping注解
时间: 2024-05-21 21:11:11 浏览: 76
以下是Java程序代码:
import java.util.Scanner;
public class HighestScore {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
// 提示用户输入学生的个数
System.out.print("请输入学生的个数:");
int numOfStudents = input.nextInt();
// 定义两个变量,分别用于存储最高分和第二高分
int highestScore = -1;
int secondHighestScore = -1;
// 定义两个变量,分别用于存储最高分和第二高分的学生名字
String highestScorer = "";
String secondHighestScorer = "";
// 循环读取每个学生的名字及其分数,并更新最高分和第二高分
for (int i = 1; i <= numOfStudents; i++) {
System.out.print("请输入第" + i + "个学生的名字:");
String name = input.next();
System.out.print("请输入" + name + "的分数:");
int score = input.nextInt();
if (score > highestScore) {
secondHighestScore = highestScore;
secondHighestScorer = highestScorer;
highestScore = score;
highestScorer = name;
} else if (score > secondHighestScore) {
secondHighestScore = score;
secondHighestScorer = name;
}
}
// 输出获得最高分和第二高分的学生名字
System.out.println("获得最高分的学生是:" + highestScorer + ",分数为:" + highestScore);
System.out.println("获得第二高分的学生是:" + secondHighestScorer + ",分数为:" + secondHighestScore);
}
}
阅读全文