排序问题
姓名 分数
jim 8.8
tom 8.6
sim 7.5
locy 5.69
lily 8.56
lilei 5.9
我要按分数排序,怎么做?
[解决办法]
public class ArrSort { public static void main(String[] args){ int[] arrInt = {4, 2, 3, 1, 6}; String[] arrStr = {"ab", "cd", "ef", "gh", "ij"}; int tmpInt; String tmpStr; for(int i = 0; i < arrInt.length - 1; ++i){ for(int j = 0; j < arrInt.length - i - 1; ++j){ if(arrInt[j] > arrInt[j+1]){ tmpInt = arrInt[j]; arrInt[j] = arrInt[j+1]; arrInt[j+1] = tmpInt; tmpStr = arrStr[j]; arrStr[j] = arrStr[j+1]; arrStr[j+1] = tmpStr; } } } for(int i = 0; i < arrInt.length; ++i){ System.out.println(arrInt[i] + "------" + arrStr[i]); } }}1------gh2------cd3------ef4------ab6------ij这个用JAVA写的arrInt = {4, 2, 3, 1, 6};arrStr = {"ab", "cd", "ef", "gh", "ij"};这两个数组上下的数据是一起的,排序之后仍然能对上号