-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLotto2.java
More file actions
86 lines (68 loc) · 1.81 KB
/
Lotto2.java
File metadata and controls
86 lines (68 loc) · 1.81 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import java.util.Scanner;
import java.util.Random;
public class Lotto2{
int[] numbers;
public Lotto2(){
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 void remake(){
Scanner s = new Scanner(System.in);
numbers = new int[6];
int i = 0;
int num = 0;
while(i < 6){
num = s.nextInt();
if(num < 1 || num > 45){
print();
continue;
}
if(check(i,num)){
print();
continue;
}
numbers[i] = num;
i++;
}
}
public void print(){
System.out.println("You can only write 1~45 numbers which don't repeat.");
}
public boolean check(int k, int m){
int check = 0;
for(int i=0; i<k; i++)
if(numbers[i] == m)
check = 1;
if(check == 1)
return true;
else
return false;
}
public static void main(String[] args){
Lotto2 l = new Lotto2();
l.printNumbers();
l.remake();
l.printNumbers();
}
}