Post

[BOJ 10869] 사칙연산

Baekjoon Online Judge 10869(Java 11)
[사칙연산] 문제 풀이

[BOJ 10869] 사칙연산

-> 문제 바로가기



시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초256 MB67471230063425020853.288%

문제


  • 두 자연수 A와 B가 주어진다. 이때, A+B, A-B, A*B, A/B(몫), A%B(나머지)를 출력하는 프로그램을 작성하시오.


입력


  • 두 자연수 A와 B가 주어진다. (1 ≤ A, B ≤ 10,000)


출력


  • 첫째 줄에 A+B, 둘째 줄에 A-B, 셋째 줄에 A*B, 넷째 줄에 A/B, 다섯째 줄에 A%B를 출력한다.


예제


1
2
// 입력
7 3
1
2
3
4
5
6
// 출력
10
4
21
2
1


알고리즘 분류








제출



내 제출


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

public class Main {
    public static void solution() throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));

        StringTokenizer st = new StringTokenizer(br.readLine(), " ");

        int a = Integer.parseInt(st.nextToken());
        int b = Integer.parseInt(st.nextToken());

        bw.write(String.valueOf(a + b));
        bw.newLine();

        bw.write(String.valueOf(a - b));
        bw.newLine();

        bw.write(String.valueOf(a * b));
        bw.newLine();

        bw.write(String.valueOf(a / b));
        bw.newLine();

        bw.write(String.valueOf(a % b));
        bw.newLine();

        bw.flush();
        bw.close();
    }

    public static void main(String[] args) throws IOException {
        solution();
    }
}


런타임메모리
132 ms14288 KB


Reference


This post is licensed under CC BY 4.0 by the author.