[Java] Scanner 클래스

하늘·2023년 2월 3일
0

[Java] 정리

목록 보기
1/3

Scanner 기본 사용 방법

Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
  • System.in은 키보드와 연결된 표준 입력 스트림(standard input stream)이다.
  • sc.nextInt(); 는 키보드로 입력한 int형 정숫값을 읽어 들이는 부분이다.

Scanner 클래스에 포함되어 있는 next 메서드

메서드자료형입력값의 범위
nextBoolean()booleantrue 또는 false
nextByte()byte-128 ~ +127
nextShort()short-32768 ~ +32767
nextInt()int-2147483648 ~ +2147483647
nextLong()long-9223372036854775808 ~ +9223372036854775807
nextFloat()float+-3.4028247E+38 ~ +-4.94065645841246544E-324
nextDouble()double+-1.79769313486231507E+378 ~ +-4.94065645841246544E-324
next()String문자열(공백, 줄 바꿈 문자로 구분)
nextLine()String문자열 1줄
profile
취뽀까지 화이띵

0개의 댓글