간단한 이야기를 만들고 있는데, 때때로 사용자가 Enter 키를 누르라는 메시지가 나타납니다. 그것은 내가 프롬프트 할 때 처음 작동하지만 다른 프롬프트가 즉시 실행됩니다. ENTER 키를 놓을 때까지 프로그램이 너무 빨리 실행되기 때문에 이미 프롬프트에 대한 검사가 실행되었습니다.자바 콘솔 이동하기 전에 ENTER 입력 프롬프트
아이디어가 있으십니까? 아래 코드.
System.out.println("...*You wake up*...");
System.out.println("You are in class... you must have fallen asleep.");
System.out.println("But where is everybody?\n");
promptEnterKey();
System.out.println("You look around and see writing on the chalkboard that says CBT 162");
promptEnterKey();
//////////////////////////////////////////////////////
public void promptEnterKey(){
System.out.println("Press \"ENTER\" to continue...");
try {
System.in.read();
} catch (IOException e) {
e.printStackTrace();
}
}
스캐너 클래스를 사용해야한다고 생각합니다. – Emrage
[이 SO 게시물] (http://stackoverflow.com/questions/7877529/java-string-scanner-input-does-not-wait-for) -info-moves-direct-to-next-stateme) ... 같은 것을 다시 배치하기 전에 다른 질문을 읽어보십시오. – starvator
앞으로는 System.out.print (System.in.read()); 무슨 일이 일어나고 있는지 보러. [이 Ascii 테이블] (http://www.asciitable.com/)은 캐리지 리턴과 개행 문자가 안으로 읽혀지고 있다고 지적합니다. – Compass