package k20231201;
import java.util.Random;
public class LottoTest {
public static void main(String[] args) throws InterruptedException {
// 추첨기를 만든다
int[] lotto = new int[45];
// 공을 넣는다
for (int i = 0; i<lotto.length; i++) {
lotto[i] = i+1;
}
// 섞기전 상태
for (int i = 0; i<lotto.length; i++) {
System.out.printf("%2d ", lotto[i]);
if ((i + 1) % 15 == 0) {
System.out.println();
}
}
System.out.println("=====================섞기 전======================");
// 섞는다
Random random = new Random();
for (int i = 0; i<1000000; i++) {
int r = random.nextInt(44) + 1;
int temp = lotto[0];
lotto[0] = lotto[r];
lotto[r] = temp;
}
for (int i = 0; i<lotto.length; i++) {
System.out.printf("%2d ", lotto[i]);
if ((i + 1) % 15 == 0) {
System.out.println();
}
}
System.out.println("=====================섞은 후======================");
// 1등 번호와 보너스 번호를 출력한다.

System.out.print("1등 번호: ");
for (int i = 0; i<6; i++) {
System.out.printf("%2d ",lotto[i]);
try {Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
System.out.printf("\n보너스 번호: %2d" , lotto[6]);
}
}

'java&eclipse 코딩 알고리즘 > 20231201' 카테고리의 다른 글
| PerfectNumber2 (0) | 2023.12.13 |
|---|---|
| PerfectNumber (0) | 2023.12.13 |
| ForTest (0) | 2023.12.13 |
| DiceTest3 (0) | 2023.12.13 |
| DiceTest2 (0) | 2023.12.13 |