public class 魏功豪_作業_大樂透照大小排列_泡沫排序法 {
public static void main(String[] args) {
int betTimes = 10;
int allBalls = 49;
int [] arrSixBall = new int [6];
int temp;
//=============================
for (int bt = 1; bt <= betTimes; bt++) {
int [] arrOriginal = new int [allBalls];
for (int i = 0; i <= arrOriginal.length - 1; i++) {
arrOriginal[i] = i + 1;
}
System.out.print("第" + bt + "注\t");
for (int times = 1; times <= 6; times++) {
int randomTakeOneBall = (int)(Math.random()*arrOriginal.length);
arrSixBall[times-1] = arrOriginal[randomTakeOneBall];
int [] arrNew = new int [arrOriginal.length - 1];
for (int i = 0; i <= (arrOriginal.length - 1) - 1; i++) {
arrNew[i] = (i < randomTakeOneBall) ? arrOriginal[i] : arrOriginal[i + 1];
}
arrOriginal = arrNew;
}
for (int i = 0; i < 6; i++) {
for (int j = i; j < 6; j++) {
if (arrSixBall[i] < arrSixBall[j]) {
temp = arrSixBall[j];
arrSixBall[j] = arrSixBall[i];
arrSixBall[i] = temp;
}
}
}
for (int x = 0; x < 6; x++) {
System.out.print((arrSixBall[x] < 10) ? " " + arrSixBall[x] + ",\t" : arrSixBall[x] + ",\t");
}
System.out.print("\n");
}
//=============================
}
}
沒有留言:
張貼留言