quilt code
[고급자바] Lotto 과제 본문
|
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
|
package study;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
public class Lotto {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while(true) {
System.out.println("===========================");
System.out.println("Lotto 프로그램");
System.out.println("--------------");
System.out.println("1.Lotto 구입");
System.out.println("2.프로그램 종료");
System.out.println("===========================");
System.out.print("메뉴선택: ");
int menuNum = Integer.parseInt(scanner.nextLine());
if(menuNum == 1) {
BuyLotto();
} else if (menuNum == 2) {
System.out.println("감사합니다.");
break;
} else {
System.out.println("입력 오류");
break;
}
}
}
public static void BuyLotto( ) {
Scanner scanner = new Scanner(System.in);
System.out.println("Lotto 구입 시작");
System.out.println("(1000원에 로또번호 하나입니다.)");
System.out.print("금액 입력: ");
int money = Integer.parseInt(scanner.nextLine());
System.out.println("행운의 로또번호는 아래와 같습니다.");
if (money > 1000) {
for(int i=1; i<=money/1000; i++) {
Set<Integer> lotto = new HashSet<>(); //중복제거
while (lotto.size() < 6) {
int random = (int)(Math.random()*45+1);
lotto.add(random);
}
System.out.println(lotto);
}
System.out.println();
System.out.println("받은 금액은 " + money + "원이고, 거스름돈은 " + money%1000 + "입니다.");
System.out.println();
}
}
}
|
cs |
'daily > 고급자바' 카테고리의 다른 글
| [고급자바] 컬렉션 프레임워크(4) (0) | 2023.02.02 |
|---|---|
| [고급자바] Student 과제 (0) | 2023.02.02 |
| [고급자바] 컬렉션 프레임워크 (3) (0) | 2023.02.01 |
| [고급자바] 컬렉션 프레임워크 (2) (0) | 2023.01.31 |
| [고급자바] 컬렉션 프레임워크 (1) (0) | 2023.01.30 |