我试图以降序输出名称和相应的分数。有一个字符串数组和另一个整数数组,我试图将两个数组关联起来。我用Arrays.sort并尝试获取索引。然后使用索引将名称排列在与相应分数类似的位置。我有这个代码,但我得到运行时错误说不幸的是,你的应用程序已停止。任何人都可以请帮助我做些什么来实现我的目标?非常感谢!按降序对整数数组进行排序并将其与其对应的字符串数组相关联
int score[]= new int[4];
score[0]= 10;
score[1]= 50;
score[2]= 20;
score[3]= 60;
String names[] = new String[4];
names[0]= "player1";
names[1]= "player2";
names[2]= "player3";
names[3]= "player4";
Arrays.sort(score);
int index_array[] = new int[4];
int m = 0;
for(m = 0; m <4; m++){
index_array[m]=Arrays.binarySearch(score ,score[m]);
l = index_array[0];
}
for(int i = 0; i<4; i++){
if(l == score[i]){
j = i;
}
}
String name = names[m];
show.setText(name + " " + Integer.toString(l));
post stacktrace – moDev 2013-02-25 19:28:16
请发布您的LogCat输出 – h4ck3d 2013-02-25 19:28:31
我相信这被称为“索引排序”。 – 2013-02-25 19:30:52