Created
July 4, 2023 12:28
-
-
Save dongsub-joung/56438d00388716946dfcb59d37a6110e to your computer and use it in GitHub Desktop.
정동섭
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 정동섭 | |
import java.util.*; | |
public class Lottery { | |
final static int MAX_SIZE= 6; | |
int[] lottery_numbers; | |
Lottery(){ | |
HashSet hashSet= new HashSet(); | |
for (int i=0; i<MAX_SIZE; i++){ | |
int num= adding_number(); | |
if (num == 0) | |
num= adding_number(); | |
hashSet.add(num); | |
} | |
int[] lottery_numbers= new int[MAX_SIZE]; | |
int idx= 0; | |
for (var e: hashSet){ | |
lottery_numbers[idx++]= (int) e; | |
} | |
Arrays.sort(lottery_numbers); | |
this.lottery_numbers= lottery_numbers; | |
} | |
private int adding_number() { | |
Random random= new Random(); | |
int number; | |
while (true){ | |
number= random.nextInt(44)+1; | |
if (number != 00) | |
return number; | |
} | |
} | |
public static void main(String[] args) { | |
System.out.println("[로또 당첨 프로그램]"); | |
System.out.printf("로또 개수를 입력해 주세요.(숫자 1 ~10):"); | |
Scanner sc= new Scanner(System.in); | |
int number= sc.nextInt(); | |
ArrayList<Lottery> lotteries= new ArrayList<>(); | |
char char_next= 'A'; | |
for (int i=0; i<number; i++){ | |
Lottery lottery= new Lottery(); | |
System.out.printf(String.format("%c ", char_next++)); | |
for (var e: lottery.lottery_numbers) | |
System.out.printf(String.format("%02d ", e)); | |
System.out.println(); | |
lotteries.add(lottery); | |
} | |
System.out.println(); | |
Lottery provider= new Lottery(); | |
System.out.println("[로또 발표]"); | |
for (var e: provider.lottery_numbers) | |
System.out.printf(e+" "); | |
System.out.println("\n"); | |
int count= 0; | |
char char_next2= 'A'; | |
for (int i=0; i<number; i++){ | |
var element= lotteries.get(i); | |
System.out.printf(String.format("%c ", char_next2++)); | |
int j =0; | |
for (var e: element.lottery_numbers){ | |
System.out.printf(String.format("%02d ", e)); | |
if (e == provider.lottery_numbers[j]){ | |
count++; | |
j++; | |
} | |
} | |
System.out.printf(String.format(" ==> %d개 일치", count)); | |
count=0; | |
System.out.println(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment