-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLotto3.java
More file actions
114 lines (85 loc) · 2.36 KB
/
Lotto3.java
File metadata and controls
114 lines (85 loc) · 2.36 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import java.util.Scanner;
import java.util.Random;
public class Lotto3{
int[] numbers;
public Lotto3(){
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 int checkLotto(int[] check){
int count = 0;
for(int i=0; i<6; i++)
if(numbers[i] == check[i])
count ++;
return count;
}
public static void main(String[] args){
Scanner s = new Scanner(System.in);
Lotto3 l = new Lotto3();
int[] number = new int[6];
l.printNumbers();
l.remake();
l.printNumbers();
for(int i=0; i<6; i++)
number[i] = s.nextInt();
int n = 0;
n = l.checkLotto(number);
if(n == 6)
System.out.println("You got Lotto");
else
System.out.println("You didn't got Lotto try next time");
}
}