JAVA - 백준 [BAEK JOON]/입출력과 사칙연산
[백준] 1000번 : A + B - JAVA (자바)
_ys2
2024. 4. 17. 22:51
728x90
반응형
https://www.acmicpc.net/problem/1000
1000번: A+B
두 정수 A와 B를 입력받은 다음, A+B를 출력하는 프로그램을 작성하시오.
www.acmicpc.net
문제
문제 풀이
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 sc = new Scanner(System.in);
사용자를 입력받기 위해 Scanner 객체를 생성한다.
int A = sc.nextInt();
int B = sc.nextInt();
정수 A, B를 입력받는다.
System.out.println(A + B);
A와 B를 더한 값을 출력한다.
sc.close();
Scanner를 닫는다. 이유는 자원누수 방지를 위해 sc.close(); 객체를 사용해서 닫는다.
피드백
이번에는 Main 실수하지 않고 잘 문제를 해결한 것 같다. 오늘도 열심히 문제를 풀어보겠다!!

코드는 깃 허브에도 올려두겠다.
Algorithm_Judge/boj/java/step/b_01_input_output_and_arithmetic_operations/p_1000.java at main · CHUNYOUNGSANG/Algorithm_Judge
Contribute to CHUNYOUNGSANG/Algorithm_Judge development by creating an account on GitHub.
github.com
반응형