首页 > 试题广场 >

(找出最高分)编写程序,提示用户输人学生的个数、每个学生的名

[问答题]
(找出最高分)编写程序,提示用户输人学生的个数、每个学生的名字及其分数,最后显示得最高 分的学生的名字。
public class Test {
	public static void main(String[] args){
	
		
		//程序说明:找出分数最高的学生
		//提示用户输入
		System.out.print("Enter the number of students:");
		
		Scanner input = new Scanner(System.in);
		int n = input.nextInt();
		String str = "",strh = "";
		double score = 0,high = 0;
			//输入学生信息
		int i = 1;
		while(i <= n)
		{
			System.out.print("Enter the name of the student:");
			str = input.next();
			System.out.print("Enter the score of the student:");
			score = input.nextDouble();
			
			if(score > high)
				{
				high = score;
				strh = str;
				}
			i++;
		}
		//显示分数最高的学生
		System.out.print("name of the top student:" + strh + "."+  "score of the top student:" + high);
    }
}

发表于 2020-02-26 13:57:50 回复(0)