第6章_数组_编程练习_Exercise6_19(成绩排名)
来源:互联网 发布:黎明三角洲淘宝店铺 编辑:程序博客网 时间:2024/04/30 05:32
/**
* 输入学生成绩和名字,按降序排列
*/
import javax.swing.JOptionPane;
public class Exercise6_19 {
public static void main(String[] args) {
String temp;
String str = "";
int number = Integer.parseInt(JOptionPane.showInputDialog("请输入学生数量:"));
int[] score = new int[number];
String[] name = new String[number];
for(int i = 0; i < number; i++){
score[i] = Integer.parseInt(JOptionPane.showInputDialog("请输入学生分数:"));
name[i] = JOptionPane.showInputDialog("输入学生姓名");
}
//冒泡排序法
for(int i = 0 ; i < score.length-1 ; i++){
for(int j = i + 1; j < score.length; j++ ){
if( score[j] > score[i]){
score[i] = score[j]+score[i];
score[j] = score[i] - score[j];
score[i] = score[i] - score[j];
temp = name[j];
name[j] = name[i];
name[i] = temp;
}
}
}
//打印成绩表
for(int i =0; i < score.length; i++){
str += score[i] + " " + name[i] + "/n";
}
JOptionPane.showMessageDialog(null, "学生成绩:" + " " + "学生的名字:/n"+str);
}
}
- 第6章_数组_编程练习_Exercise6_19(成绩排名)
- 第6章_数组_编程练习_Exercise6_5
- 第6章_数组_编程练习_Exercise6_25(二维数组的相乘)
- 红皮书c#高级编程(第6版)_第5章_数组
- 第4章_循环_编程练习4.9计算最高分和次高分
- 第4章_循环_编程练习4.16求整数的因子
- 第5章_方法_编程练习5.4(数字倒序输出)
- 第5章_方法_编程练习5.19(得到三角形的面积)
- 第5章_方法_编程练习5_22(平方根的近似求法)
- 第9章_继承和多态_编程练习_Exercise9_2按要求设计类
- 红皮书c#高级编程(第6版)_第4章_继承_实现继承
- 红皮书c#高级编程(第6版)_第9章_泛型_概论
- 第5章_数组
- 1004_成绩排名 (20)
- 第2章_基本数据类型和基本操作_编程练习Exercise2.11通过控制台进行大小写的切换
- 第8章_字符串与文本I/O_编程练习_8.9_十进制转化为十六进制
- 第03章 CORE C++_枚举_数组_结构_指针(I)
- 红皮书c#高级编程(第6版)_第2章_c#基础_变量
- 判断字节序小程序
- ThinkPHP 学习笔记
- c# 请求需要cookie支持的页面(保持请求的cookie)
- sed行对象【列表】和单个字符对象【替换】
- iphone关于self.用法的一些总结
- 第6章_数组_编程练习_Exercise6_19(成绩排名)
- python 处理字符ASICII码
- 第6章_数组_编程练习_Exercise6_25(二维数组的相乘)
- 将m个苹果放入n个盘子的问题
- javascript中替换表单中的全角字符为半角字符
- 查杀木马 QQ电脑管家 vs. 金山卫士
- Linux 防火墙
- CPU 调度
- JSTL1.1函数标签库(functions)如fn:length