(자바) 스캐너 클래스 및 버퍼 개행 문자

스캐너 클래스는 다음과 같습니다.

소량의 데이터수광 및 처리 중(java.util.Scanner)

넥스트인트(), 넥스트()


공백 없이 정수/문자열을 입력하세요.
개행 무시(‘\n’)

다음 줄()


공백이 있는 문자열, 한 줄 입력
개행 문자 무시(‘\n’) x

nextInt(), next() 다음에 nextLine()을 하면?
버퍼에 남아 있는 개행 문자nextLine()은 즉시 읽습니다.

import java.util.Scanner;

public class ScannerAndNextLineTest {
    public static void main(String() args) {
        Scanner sc = new Scanner(System.in);
        System.out.print("이름: ");
        sc.next();
        System.out.print("나이: ");
        sc.nextInt();
        System.out.print("주소: ");
        sc.nextLine(); // \n이 입력되어 바로 넘어간다
        System.out.println("end..");
    }

}

솔루션
: sc.nextLine();다음으로 줄 바꿈 삭제

import java.util.Scanner;

public class ScannerAndNextLineTest {
    public static void main(String() args) {
        Scanner sc = new Scanner(System.in);
        System.out.print("이름: ");
        sc.next();
        System.out.print("나이: ");
        sc.nextInt();

        //개행문자 비우기
        sc.nextLine();

        System.out.print("주소: ");
        sc.nextLine(); // 버퍼에 개행문자를 비웠으므로 입력할 수 있다
        System.out.println("end..");
    }
}