【发布时间】:2013-02-11 01:27:57
【问题描述】:
我正在尝试按降序输出名称和相应的分数。有一个字符串数组和另一个整数数组,我试图将这两个数组联系起来。我使用 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));
【问题讨论】:
-
请发布您的 LogCat 输出
-
我相信这被称为“索引排序”。
标签: java android arrays sorting indexing