java键盘循环输入5个学生的成绩_键盘录入5个学生的信息根据总分从高到低输出在控制台...

该博客介绍了如何使用Java编程,通过键盘循环输入5个学生的名字及三科成绩,然后根据总分从高到低进行排序,并在控制台输出排序后的学生信息。

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

第一部分:

public class Student {

private String name;

private Integer chinese;

private Integer math;

private Integer english;

public Student(){

super();

}

public Student(String name,Integer chinese,Integer math,Integer english){

super();

this.name = name;

this.chinese = chinese;

this.math = math;

this.english = english;

}

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public Integer getChinese() {

return chinese;

}

public void setChinese(Integer chinese) {

this.chinese = chinese;

}

public Integer getMath() {

return math;

}

public void setMa

你可以使用Scanner类来获取用户输入,然后计算每个学生总分排序。以下是一个简单的Java程序示例: ```java import java.util.*; class Student { String name; int chineseScore; int mathScore; int englishScore; public Student(String name, int chineseScore, int mathScore, int englishScore) { this.name = name; this.chineseScore = chineseScore; this.mathScore = mathScore; this.englishScore = englishScore; } public int getTotalScore() { return chineseScore + mathScore + englishScore; } } public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); List<Student> students = new ArrayList<>(); System.out.println("请输入5学生信息(格式:姓名,语文成绩,数学成绩,英语成绩):" ); for (int i = 0; i < 5; i++) { System.out.print("第" + (i + 1) + "名学生:"); String name = scanner.nextLine(); int[] scores = new int[3]; for (int j = 0; j < 3; j++) { System.out.print("第" + (j + 1) + "门课程得分:"); scores[j] = scanner.nextInt(); } students.add(new Student(name, scores[0], scores[1], scores[2])); } Collections.sort(students, Comparator.comparingInt(Student::getTotalScore).reversed()); System.out.println("\n按总分学生信息:"); for (Student student : students) { System.out.printf("%s 总分:%d%n", student.name, student.getTotalScore()); } } } ``` 这个程序首先创建一个Student类用于存储学生信息,并包含计算总分的方法。在main函数里,读取用户的输入,创建Student对象并保存到list中,然后根据总分对list进行降序排序
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值