-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalculator.java
More file actions
53 lines (45 loc) · 2.04 KB
/
Calculator.java
File metadata and controls
53 lines (45 loc) · 2.04 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
import java.util.Scanner;
public class Calculator {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while (true) {
System.out.println("==== 지원하는 연산 ====");
System.out.println("1. + (더하기)");
System.out.println("2. - (빼기)");
System.out.println("3. * (곱하기)");
System.out.println("4. / (몫)");
System.out.println("5. % (나머지)");
System.out.println("6. 종료");
System.out.println("====================");
System.out.println();
System.out.print("수행하고 싶은 연산을 선택해주세요>> ");
int operationNum = scanner.nextInt();
if (operationNum == 6) {
System.out.println("프로그램이 종료되었습니다.");
break;
}
System.out.print("첫번째 피연산자를 입력해주세요>> ");
int operand1 = scanner.nextInt();
System.out.print("두번째 피연산자를 입력해주세요>> ");
int operand2 = scanner.nextInt();
switch (operationNum) {
case 1:
System.out.println(operand1 + " + " + operand2 + " = " + (operand1 + operand2));
break;
case 2:
System.out.println(operand1 + " - " + operand2 + " = " + (operand1 - operand2));
break;
case 3:
System.out.println(operand1 + " * " + operand2 + " = " + (operand1 * operand2));
break;
case 4:
System.out.println(operand1 + " / " + operand2 + " = " + (operand1 / operand2));
break;
case 5:
System.out.println(operand1 + " % " + operand2 + " = " + (operand1 % operand2));
break;
}
}
scanner.close();
}
}