java/코드 리뷰
4. control - (2) Lotto2 (for, if문 사용)
Astaroth아스
2020. 3. 23. 15:02
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 control;
import java.util.Scanner;
public class Lotto2 {
public static void main(String[] args) {
/*
금액을 입력받는다
금액은 1000원 단위의 값만 입력받는다
로도 번호를 입력된 금액만큼 발행한다
1000원당 1세트씩 발행한다
*/
System.out.print("금액을 입력하세요 : ");
Scanner sc = new Scanner(System.in);
int money = sc.nextInt();
int count = 0;
int lotto = 0;
count = money / 1000;
for (int i=1; i<=count*6; i++) {
lotto = (int) (Math.random() * 45 + 1);
System.out.print(lotto + " ");
if(i%6==0) {
System.out.println();
}
}
int don = money - count * 1000;
System.out.println("잔돈 : " + don);
}
}
/* 내 이중 풀이
package control;
import java.util.Scanner;
public class Lotto2 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int money = sc.nextInt();
int much = money / 1000;
if (much >= 1) {
for (int i = 0; i < much; i++) {
for (int j = 0; j < 6; j++) {
int lotto = (int) (Math.random() * 45 + 1);
System.out.print(lotto + " ");
}
System.out.println();
}
} else {
System.out.println("금액이 부족합니다");
}
}
}
*/
|