Q) BAEKJOON / JAVA / 10869 : 사칙연산
https://www.acmicpc.net/problem/10869
A)
- [1] Scanner
import java.util.Scanner;
public class Main {
public static void main(String args[]) {
//스캐너 선언
Scanner sc = new Scanner(System.in);
//nextInt() 활용
//정수형 변수에 저장
int A = sc.nextInt();
int B = sc.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);
//스캐너 종료
sc.close();
}
}
- [2] BufferedReader
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
public static void main(String args[]) throws IOException {
//BufferedReader 선언
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
//readLine()으로 행 읽어오기
String str = br.readLine();
//StringTokenizer로 문자열 토큰 단위로 구분
StringTokenizer st = new StringTokenizer(str, " ");
//nextToken() 활용 토큰 값 가져오기
//nextToken()은 문자열 반환
//parseInt로 정수형으로 변환 후 저장
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);
}
}