import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in);
int A = in.nextInt(); int B = in.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); } }
Scanner를 사용했을 경우 코드 작성방법이지만 시간이 느리다는 단점이 있다.
import java.io.*; import java.util.*;
public class Main{ 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); } }