입출력 - Scanner와 개행 문자

ino5·2021년 6월 6일
	public static void main(String[] args) {
		String a = "23\nasd\nbc\n";
		Scanner sc = new Scanner(a);
		System.out.print(sc.nextInt());
		String b = sc.nextLine();
		System.out.print(b);
		System.out.print(sc.nextLine());
		System.out.print(sc.nextLine());
		
		System.out.println(b.equals(""));
		sc.close();
	}
}

next(), nextInt(), etc

문자열에서 \n 직전까지만 읽는다. 만약 문자열 가장 앞이 \n일 경우 읽을 값이 없어 예외가 발생한다.

nextLine()

문자열에서 \n 까지 읽지만 \n은 버린다.

profile
지금은 네이버 블로그만 해요... https://blog.naver.com/chero77

0개의 댓글