자바 Scanner 클래스

자바 Scanner 클래스

백준알고리즘 1000

1. Scanner

1-1. next + 자료형() => 자료형에 따라 입력 받음.

1-2. nextLine() => 한 줄을 전체 입력 받음.(개행문자까지 받을 수 있기 때문에 buffer형 변수에 한번 더 받아줌)

1-3. next() => 공백 전까지 입력 받음.

1-4. hasNextInt() => Scanner에서 정수를 입력받은 경우 ? true : false 반환

1-5. System.in => 입력한 값을 Byte 단위로 읽음. 실행 프로그램에서 하나만 생성되고, 여러개의 객체들이 공유하는 형태로 사용함.

1-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); } }

from http://zeromi.tistory.com/78 by ccl(A) rewrite - 2021-11-23 14:02:04