-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathWhileExamp.java
More file actions
43 lines (40 loc) · 1.13 KB
/
Copy pathWhileExamp.java
File metadata and controls
43 lines (40 loc) · 1.13 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
import java.util.Scanner;
// while 문 예제
public class WhileExamp {
public static void main(String[] args) {
boolean flag = false;
Scanner scan = new Scanner(System.in);
int sel = 0;
while(!flag) {
System.out.println("------- Menu -------");
System.out.println("| 1. 2. 3. 99.exit |");
System.out.print("Select Number : ");
sel = scan.nextInt();
// if(sel == 99) flag = true;
switch(sel) {
case 1: // 합 구하기
int sum = 0;
for (int i = 1; i <= 10; i++) {
sum += i;
}
System.out.println("1부터 10까지 합: " + sum);
break;
case 2: // 1~6 중에 하나의 값 출력
int outNum = (int) (Math.random() * 6) + 1;
System.out.println("1~6 중 랜덤 출력 값 --> " + outNum);
break;
case 3: // 구구단 3단 출력
System.out.println("### 구구단 3단 ###");
for(int i = 1; i <= 9; i++)
System.out.printf(" %2d x %2d = %2d\n", sel, i, (sel*i));
break;
case 99:
flag = true;
break;
default :
System.out.println("잘못된 메뉴를 선택하셨습니다." );
}
}
System.out.println("프로그램 종료");
}
}