Console Input(콘솔 입력)

CODEDRAGON Development/Java

반응형


 

Console Input(콘솔 입력)

·       과거의 입력방식은 프로그래밍 언어에 비해 복잡했습니다.

·       부분을 Scanner클래스를 통해 해결하여 아래와 같이 쉽게 입력 받을 있게 되었습니다.

 

기존 과거방식

(정수 입력)

BufferedReader bufferedReader = 

new BufferedReader(new InputStreamReader(System.in));

String str = bufferedReader.readLine();

int num = Integer.parseInt(str);

개선된 방식

(정수 입력)

Scanner scanner = new Scanner(System.in);

int num = scanner.nextInt();

 

 

 

 

Scanner 클래스

·       Scanner 클래스는 단순히 키보드의 입력만을 목적으로 디자인된 클래스가 아니라

·       다양한 리소스를 대상으로 입력을 받을 있도록 정의된 클래스입니다.

 

 

 

 

Scanner 클래스 생성자

·       Scanner(File source)

·       Scanner(InputStream source)

·       Scanner(Readable source)

·       Scanner(String source)

 

 

 

 

Scanner 클래스 메소드

읽어 들일 데이터의 유형에 따른 메소드

·       public boolean nextBoolean()

·       public byte nextByte()

·       public short nextShort()

·       public int nextInt()

·       public long nextLong()

·       public float nextFloat()

·       public double nextDouble()

·       public String nextLine()

 

 

 


반응형