충분히 쌓여가는
백준[Java] 10869번 사칙연산 본문
https://www.acmicpc.net/problem/10869
문제풀이
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int A = scan.nextInt();
int B = scan.nextInt();
System.out.println(A + B);
System.out.println(A - B);
System.out.println(A * B);
System.out.println(A / B);
System.out.println(A % B);
}
}
- 백준 1000문제와 같이 풀어주면 됨
- 사칙연산 문제이기 때문에 간단한 문제
주의사항
- 공백 단위로 입력해야함
문제풀이 2
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class _10869_2 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String str = br.readLine();
StringTokenizer st = new StringTokenizer(str, " ");
int A = Integer.parseInt(st.nextToken());
int B = Integer.parseInt(st.nextToken());
System.out.println(A+B);
System.out.println(A-B);
System.out.println(A*B);
System.out.println(A/B);
System.out.println(A%B);
}
}
문제풀이 3
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class _10869_3 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine(), " ");
int A = Integer.parseInt(st.nextToken());
int B = Integer.parseInt(st.nextToken());
System.out.println(A+B);
System.out.println(A-B);
System.out.println(A*B);
System.out.println(A/B);
System.out.println(A%B);
}
}
문제풀이 4
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class _10869_4 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] str = br.readLine().split(" ");
int A = Integer.parseInt(str[0]);
int B = Integer.parseInt(str[1]);
System.out.println(A+B);
System.out.println(A-B);
System.out.println(A*B);
System.out.println(A/B);
System.out.println(A%B);
}
}
'IT > Java[백준]' 카테고리의 다른 글
백준[Java] 3003번 킹, 퀸, 룩, 비숍, 나이트, 폰 (0) | 2023.02.13 |
---|---|
백준[Java] 10926번 ??! (0) | 2023.02.13 |
백준[Java] 1008번 A/B (1) | 2023.02.13 |
백준[Java] 10998번 AXB (0) | 2023.02.12 |
백준[Java] 1001번 A-B (0) | 2023.02.12 |