
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int A = sc.nextInt();
int B = sc.nextInt();
System.out.println(A+B);
sc.close();
}
}
Scanner 클래스의 사용

import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int A = sc.nextInt();
int B = sc.nextInt();
System.out.println(A-B);
sc.close();
}
}
sc.close();을 해야하는 이유
필수는 아니지만, JAVA에서 resource(메모리, 입출력 스트림 등)을 사용하는 경우
sc.close();를 호출함으로써 리소스들의 낭비를 막고,
메모리 누수와 같은 예기치 않은 문제를 방지할 수 있다.