• 문제 링크
https://www.acmicpc.net/problem/5613
• 풀이 코드
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
public class Main {
static int n;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
n = Integer.parseInt(br.readLine());
String s;
while ((s = br.readLine()).charAt(0) != '=') calc(s.charAt(0), Integer.parseInt(br.readLine()));
bw.write(String.valueOf(n));
bw.flush();
}
private static void calc(char opt, int opr) {
switch (opt) {
case '+':
n += opr;
break;
case '-':
n -= opr;
break;
case '*':
n *= opr;
break;
default:
n /= opr;
}
}
}
'Problem Solving > Baekjoon' 카테고리의 다른 글
[백준] 10709 기상캐스터 - Implementation / Java (0) | 2025.03.14 |
---|---|
[백준] 5523 경기 결과 - Implementation / Java (0) | 2025.03.13 |
[백준] 2774 아름다운 수 - Implementation / Java (0) | 2025.03.11 |
[백준] 3062 수 뒤집기 - Implementation / Java (0) | 2025.03.10 |
[백준] 2783 삼각 김밥 - Implementation / Java (0) | 2025.03.09 |
댓글