import java.util.*;
public class LotteryDrawing
{
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
System.out.print("How many numbers draw?");
int k = in.nextInt();
System.out.print("What is highest number?");
int n = in.nextInt();
// 배열을 1, 2, 3 .... n 으로 채워라
int[] numbers = new int[n];
for (int i = 0; i<numbers.length; i++)
numbers[i] = i + 1;
int[] result = new int[k];
for (int i = 0;i < result.length; i++)
{
// 0부터 n-1까지 랜덤 인덱스 만들어라
int r = (int)(Math.random()*n);
// pick the elemnet at the random location and copy
result[i] = numbers[r];
// move last elemnet into random location for uniqueness
numbers[r] = numbers[n-1];
n--; // reduse the size because of uniqueness
}
Arrays.sort(result);
System.out.println("Bet as follow. It'll make you rich!");
for(int r : result)
System.out.println(r);
}
} end of lottery drawn class
'📌 java > Object-oriented Programming' 카테고리의 다른 글
Homework_W2-02 (0) | 2020.03.27 |
---|---|
Employee.java (0) | 2020.03.27 |
java - txt.file (0) | 2020.03.26 |
java.util.Arrays - Arrays 클래스 (0) | 2020.03.26 |
java.util.Scanner (0) | 2020.03.25 |