gpt4 book ai didi

java - 寻找最高分

转载 作者:行者123 更新时间:2023-11-30 06:16:03 26 4
gpt4 key购买 nike

<分区>

我编写了一个程序,提示用户输入学生姓名和分数。最后显示得分最高的学生。

这是我的代码以及我应该做什么。

public class Student {

public static void main(String[] args) {
Scanner input = new Scanner(System.in);
final int numberOfStudent = 10;
int count = 0;
int highestScore = 0;
String highestScorer = "";
String x= "";
int y;
while (count < numberOfStudent) {
System.out.println("Enter student's name and score.");
x = input.next();
y = input.nextInt();
count++;
if (highestScore < y){
highestScore = y;
highestScorer = x;
}

}
System.out.println(highestScore +" "+ highestScorer);
}

}

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com