public class Test {
/**
* 现在有个数组 需要给排序 但是序列号不能改变,因为序列号对应另外一个数组的值。
* 比如 score[1]=59; score[2]=100;
* score[3]=80; score[4]=36; score[5]=60; 排序结果是:100,80,60 59 36
* 也就是score[2]=100,score[3]=80,score[5]=60,score[1]=59,score[4]=36;
*
* @param args
*/
public static void main(String[] args) {
int[] data1 = { 59, 100, 80, 36, 60 };
String[] temp = new String[data1.length];
for (int i = 1; i < data1.length + 1; i++) {
temp[i - 1] = "score[" + i + "]=" + data1[i - 1];
}
for (int i = 0; i < data1.length; i++) {
for (int j = i + 1; j < data1.length; j++) {
if (data1[i] < data1[j]) {
String t = temp[i];
int t1 = data1[i];
temp[i] = temp[j];
data1[i] = data1[j];
temp[j] = t;
data1[j] = t1;
}
}
}
for (String s : temp) {
System.out.println(s);
}
}
}
//原理:把字符串存到字符串数组中,然后数值排序的同时将字符串数组进行排序!
取消
评论