java实验题——学生成绩排序并打印
2016-04-01 13:09
489 查看
编写一个程序,提示用户输入学生数量、各自的姓名和他们的成绩,并按照成
绩的降序来打印学生的姓名。
绩的降序来打印学生的姓名。
import java.util.*; class StudentInfo{ private String name; private int score; public String getName() { return name; } public void setName(String name) { this.name = name; } public int getScore() { return score; } public void setScore(int score) { this.score = score; } public void sort(StudentInfo[] stu,int count) { StudentInfo temp; for(int i=0;i<count;i++) { for(int j=0;j<count-i-1;j++) { if (stu[j].getScore()<stu[j+1].getScore()) { temp=stu[j]; stu[j]=stu[j+1]; stu[j+1]=temp; } } } } public void print(StudentInfo[] stu,int count){ for (int i=0; i<count;i++) { System.out.println(stu[i].getName()+" "+stu[i].getScore()); } } } public class ScoreSort { public static void main(String[] args){ StudentInfo s=new StudentInfo(); StudentInfo[] stu= new StudentInfo[20]; Scanner input= new Scanner(System.in); System.out.println("请输入学生个数:"); int count=input.nextInt(); int num=0; while(num<count) { System.out.println("请输入第"+(num+1)+"个学生的姓名和分数:"); Scanner scan=new Scanner(System.in); String strLine=scan.nextLine(); String[] strLineArr = strLine.split(" "); StudentInfo st = new StudentInfo(); st.setName(strLineArr[0]); st.setScore(Integer.parseInt(strLineArr[1])); stu[num]=st; num++; } s.sort(stu,count); System.out.println("排序后的学生信息为:"); s.print(stu,count); } }
相关文章推荐
- SpringMVC——接收请求参数和页面传参
- Eclipse修改项目包名(简单几步搞定)
- eclipse使用技巧-自动提示
- java JDBC通用BaseDao升级版0.3
- Java入门:一些初学者需要掌握的基础算法程序——二分查找
- java JDBC通用BaseDao升级版0.2
- JAVA JDBC通用BaseDao版0.1
- Openfire4.0.2源码部署到Eclipse
- MAVEN 工程打包resources目录外的更多资源文件
- java中Socket编程
- java集合的讲解
- JAVA·多线程:线程优先级
- springMVC4(2)请求映射全面分析
- 找不到或无法加载主类 com.sun.tools.javac.Main
- [JAVA · 初级]:14.数组
- 解析java中对象的"引用"
- Java处理java.util.ConcurrentModificationException异常
- 【撸码师的备忘录】 Java bean 与 xml 互相转化-JDK Marshaller
- 10分钟-JavaWeb入门-登陆功能实现
- maven中解决javax.servlet.jsp.PageContext cannot be resolved to a type