문제

https://www.acmicpc.net/problem/5613


문제 풀이

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
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int sum = sc.nextInt();
        while (true) {
            String str = sc.nextLine();
            if (str.equals("=")) {
                break;
            }
            switch (str) {
                case "+":
                    sum += sc.nextInt();
                    break;
                case "-":
                    sum -= sc.nextInt();
                    break;
                case "*":
                    sum *= sc.nextInt();
                    break;
                case "/":
                    sum /= sc.nextInt();
                    break;
                default:
                    break;
            }
        }
        System.out.println(sum);
    }
}

카테고리:

업데이트:

댓글남기기