728x90
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a, b;
a = sc.nextInt();
b = sc.nextInt();
System.out.println(a+b);
}
}
우선 입력을 받기 위해 Scanner 클래스를 import 해준다.
Scanner sc = new Scanner(System.in);
위와 같이 Scanner 객체를 생성해주고
(System.in 은 키보드를 통해 입력받는 자바의 기본적인 언어라고 한다.)
각 변수에 sc.nextInt(); 를 통하여 입력값을 변수에 저장해주었다.
728x90
'백준 단계별' 카테고리의 다른 글
[Java] 백준 2753: 윤년 (2) | 2023.01.03 |
---|---|
[Java] 백준 9498: 시험 성적 (0) | 2023.01.03 |
[Java] 백준 2588: 곱셈 (0) | 2022.07.27 |
[Java] 백준 10926: ??! (0) | 2022.07.27 |
[Java] 백준 10171번: 고양이 (0) | 2022.07.26 |