android创建高分检查
我试图创建某种循环,检查数组中的高分值,如果它高于其他值,则将其添加到数组中,并将所有较低的值下移 例如,该数组称为android创建高分检查,android,arrays,Android,Arrays,我试图创建某种循环,检查数组中的高分值,如果它高于其他值,则将其添加到数组中,并将所有较低的值下移 例如,该数组称为整数highScoreArray[12、9、8、7],其中包含4个值。我有另一个数组,它保存获得高分的相应日期,称为字符串highDateArray[“12/5/11”,“3/4/11”,“4,4/12”,“6/6/10”] 如何向数组添加新值和相应的日期?i、 e.如果新值为“10”,日期为“5/29/12” 我不想在highScoreArray[]上使用sort命令,因为这样我
整数highScoreArray[12、9、8、7]
,其中包含4个值。我有另一个数组,它保存获得高分的相应日期,称为字符串highDateArray[“12/5/11”,“3/4/11”,“4,4/12”,“6/6/10”]
如何向数组添加新值和相应的日期?i、 e.如果新值为“10”,日期为“5/29/12”
我不想在highScoreArray[]
上使用sort命令,因为这样我将无法跟踪相应值在highDateArray[]
中的位置。我希望在两个单独的线性布局中,在两列文本中对两个数组进行排序,因此尝试将它们分开,我是否使这变得更加困难
for (int i = 0; i < highScoreArray.length; i++)
{
if(newHighScore>=highScoreArray[i])
{
// DO SOMETHING
}
}
for(int i=0;i=highScoreArray[i])
{
//做点什么
}
}
如何使用存储值和相应的日期?
并使用值对它们进行排序
希望这些链接对您有所帮助
如何使用存储值和相应的日期? 并使用值对它们进行排序 希望这些链接对您有所帮助
您可以创建一个对象并实现Compariable以使其更简单
public class HighScore implements Comparable {
private int score;
private Date date; // Or you can just use String
// Getters/Setters here
...
public int compareTo(HighScore anotherScore) {
// Checking here
// Return 0 if this and anotherScore is same
// Return 1 if this greater than anotherScore
// Return -1 if this smaller than anotherScore
}
}
所以在你的循环中
for (int i = 0; i < highScoreArray.length; i++) {
HighScore highScore = highScoreArray[i];
if (newHighScore.compareTo(highScore) > 0) {
// Do something
}
}
for(int i=0;i0){
//做点什么
}
}
您可以创建一个对象并实现Compariable以使其更简单
public class HighScore implements Comparable {
private int score;
private Date date; // Or you can just use String
// Getters/Setters here
...
public int compareTo(HighScore anotherScore) {
// Checking here
// Return 0 if this and anotherScore is same
// Return 1 if this greater than anotherScore
// Return -1 if this smaller than anotherScore
}
}
所以在你的循环中
for (int i = 0; i < highScoreArray.length; i++) {
HighScore highScore = highScoreArray[i];
if (newHighScore.compareTo(highScore) > 0) {
// Do something
}
}
for(int i=0;i0){
//做点什么
}
}
您是否尝试过创建某种类型的HighScore
对象,该对象包含一个int
字段作为分数,一个字符串作为日期?不会回答你的问题,但这可能会让事情变得更容易;它将保持分数与正确的日期配对,您可以让HighScore
对象实现compariable
,以便您可以对它们的数组进行排序。您是否尝试过创建某种HighScore
对象,该对象的字段为分数的int
,为日期的字符串?不会回答你的问题,但这可能会让事情变得更容易;它将保持分数与正确的日期配对,并且您可以使用HighScore
对象实现compariable
,以便对它们的数组进行排序。