Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //This code will simulate the lottery draw
- import java.util.Scanner;
- public class Task2 {
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- System.out.println("Enter from how many numbers we extract: ");
- int n = input.nextInt();
- System.out.println("Enter how many numbers we extract:");
- int k = input.nextInt();
- int[] arr = new int[k];
- input.close();
- for(int i = 0; i < k; i++)
- {
- int random = (int) (Math.random() * n) + 1;
- for (int j = 0; j < i; j++ )
- {
- if (arr[j] == random)
- {
- random = (int) (Math.random() * n) + 1;
- j = -1;
- }
- }
- arr[i] = random;
- }
- for(int i = 0; i < k; i ++)
- System.out.println(arr[i] + " ");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement