-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLotto.java
More file actions
41 lines (36 loc) · 989 Bytes
/
Lotto.java
File metadata and controls
41 lines (36 loc) · 989 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import java.util.Scanner;
import java.util.Random;
public class Lotto{
int[] numbers;
public Lotto(){
numbers = new int[6];
Random rand = new Random();
for(int i = 0; i<6; i++){
numbers[i] = rand.nextInt(45)+1;
for(int j=0; j<i; j++)
if(numbers[i] == numbers[j])
i--;
}
}
public void printNumbers(){
for(int i = 0; i<6; i++)
System.out.printf("%d ",numbers[i]);
System.out.println();
}
public void remakeAuto(){
numbers = new int[6];
Random rand = new Random();
for(int i = 0; i<6; i++){
numbers[i] = rand.nextInt(45)+1;
for(int j=0; j<i; j++)
if(numbers[i] == numbers[j])
i--;
}
}
public static void main(String[] args){
Lotto l = new Lotto();
l.printNumbers();
l.remakeAuto();
l.printNumbers();
}
}