Java语言程序设计(基础篇)第十版 5.8 5.9

本文介绍了一个使用Java编写的程序,该程序能够接收用户输入的学生数量和每个学生的分数,然后找出最高分及其对应的学生姓名,并在第二个示例中找出第二高分。程序利用了Scanner类从用户处获取输入。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


public class J5_8 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		java.util.Scanner input = new java.util.Scanner(System.in);
		System.out.print("Enter the number of students: ");
		
		int student = input.nextInt();
		String name = "ABC";
		double score = 0;
		for(int i = 0;i<student;i++)
		{
			System.out.print("input the "+i+"Student information: ");
			double scores = input.nextDouble();
			String names = input.nextLine();
			
			if(scores >score) {
				score = scores;
				name  = names;
			}
			
		}
		System.out.println("The higly score Student is: "+name+"  score is "+score);
		
	}

}

public class J5_9 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		java.util.Scanner input = new java.util.Scanner(System.in);
		System.out.print("Enter the number of students: ");
		
		int student = input.nextInt();
		String name = "ABC";
		double score = 0;
		String name1 = "CBA";
		double score1 = 0;
		for(int i = 1;i<=student;i++)
		{
			System.out.print("input the "+i+"Student information: ");
			double scores = input.nextDouble();
			String names = input.nextLine();
			
			if(scores >score) {
				score = scores;
				name  = names;
			}
			else if(scores > score1)
			{
				score1 = scores;
				name1 = names;
			}
			
		}
		System.out.println("The higly score Student is: "+name1+"  score is "+score1);
		System.out.println("The highest score Student is: "+name+"  score is "+score);

	}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值