-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChapter4_7.java
More file actions
68 lines (43 loc) · 1.49 KB
/
Chapter4_7.java
File metadata and controls
68 lines (43 loc) · 1.49 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
package thisIsJava;
import java.util.Scanner;
public class Chapter4_7 {
public static void main(String[] args) {
boolean run = true;
int balance = 0;
while(run) {
System.out.println("--------------------------------------");
System.out.println("1. 예금 | 2. 출금 | 3. 잔고 | 4. 종료");
System.out.println("--------------------------------------");
System.out.print("선택 > ");
int choice;
int deposit;
int withdraw;
Scanner sc = new Scanner(System.in);
choice = sc.nextInt();
if(choice > 0 && choice < 5) {
if(choice == 1) {
System.out.print("예금액 > ");
Scanner depositSc = new Scanner(System.in);
deposit = depositSc.nextInt();
balance += deposit;
System.out.println();
} else if(choice == 2) {
System.out.print("출금액 > " );
Scanner withdrawSc = new Scanner(System.in);
withdraw = withdrawSc.nextInt();
balance -= withdraw;
if(balance < 0) {
System.out.println("잔액이 부족하여 출금할 수 없습니다.");
}
System.out.println();
} else if(choice == 3) {
System.out.print("잔고 > " + balance + "\n");
System.out.println();
} else break;
} else {
System.out.println("1부터 4까지의 숫자만 입력해주세요.\n");
}
}
System.out.println("프로그램 종료");
}
}