728x90
백준알고리즘 1000
Scanner
1. next + 자료형() => 자료형에 따라 입력 받음.
2. nextLine() => 한 줄을 전체 입력 받음.(개행문자까지 받을 수 있기 때문에 buffer형 변수에 한번 더 받아줌)
3. next() => 공백 전까지 입력 받음.
4. hasNextInt() => Scanner에서 정수를 입력받은 경우 ? true : false 반환
5. System.in => 입력한 값을 Byte 단위로 읽음. 실행 프로그램에서 하나만 생성되고, 여러개의 객체들이 공유하는 형태로 사용함.
6. NoSuchElementException => 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);
}
}
728x90
'Algorithm' 카테고리의 다른 글
수열 StringTokenizer 활용 (0) | 2021.11.26 |
---|---|
자바 BufferedReader, BufferedWriter, InputStreamReader, OutputStreamWriter, StringTokenizer (0) | 2021.11.25 |
자바 윤년, 평년 (0) | 2021.11.25 |
자바 세자리 연산 과정 (0) | 2021.11.25 |
java.util.NoSuchElementException (0) | 2021.11.25 |
자바 이스케이프 시퀀스, 길이 반환, 배열 초기화 (0) | 2021.10.28 |
반복문 사용 개행 출력 (0) | 2021.10.28 |
자바 main 함수 (0) | 2021.10.28 |