1. 程式人生 > >降序排列

降序排列

message 姓名 edi pos ati str new dia +=

public static void main(String[]aaa){
String [] name = new String[5];
int [] salary = new int[5];
for (int i = 0; i < salary.length; i++) {
String a = JOptionPane.showInputDialog
(null,"請輸入第"+(i+1)+"人的姓名:");
int b =Integer.parseInt(JOptionPane.showInputDialog
(null,"請輸入第"+(i+1)+"人的工資"));
name[i]=a;
salary[i]=b;
}
for (int i = 0; i < salary.length; i++) {
for (int j = i+1; j < salary.length; j++) {
if (salary[i]<salary[j]) {
int c = salary[i];
salary[i]=salary[j];
salary[j]=c;
String d = name[i];
name[i]=name[j];
name[j]=d;
}
}
}
String s =" ";
for (int i = 0; i < salary.length; i++) {
s += name[i]+":"+salary[i]+"\n";
}
JOptionPane.showMessageDialog(null, "員工工資表:"+s+"\t");
}

降序排列