我想編寫代碼來洗牌數組而不使用集合。陣列洗牌不工作
我的洗牌代碼
量
private double amounts[] = { 0, 0.01, 1000000, 25, 250000, 75, 50, 1000,
200, 100, 400000, 750, 5000, 750000, 500, 100000, 300, 75000, 800,
20, 300000, 10, 50, 750, 25, 5, 1 };
public void Shuffle(){
Random rgen = new Random();
for (int i=0; i > amounts.length; i++) {
int randomPosition = rgen.nextInt(amounts.length);
double temp = amounts[i];
amounts[i] = amounts[randomPosition];
amounts[randomPosition] = temp;
}
}
在這裏啓動它
public void casesSetup() {
for (int i = 0; i < briefcase.length; i++) {
if (i == 0) {
} else {
briefcase[i] = new Briefcase();
double value = amounts[i];
briefcase[i].setAmount(value);
briefcase[i].setFace(i);
}
}
}
我的問題是,他們沒有被隨機任何人有一個想法,爲什麼代碼?
試着做'我<的amount.length'而不是'> – Juan