-2
이것은 문자 인 경우 입력 및 루프의 유효성을 검사하는 데 사용되는 코드의 일부이지만 문자가 입력되면 무한 루프가 발생하지만 정수이면 익숙한. 나는 무한 루프를 일으키는 것이 무엇인지 모르지만 어떤 도움을 주시면 감사하겠습니다.자바 무한 루프, 유효성 검사 동안
System.out.println("Please type in a mark and enter -1 to end the program");
while (mark != -1) {
if (in.hasNextInt()) {
mark = in.nextInt();
}
else {
System.out.println("Please input an integer: ");
}
'System.out.println ("정수를 입력하십시오 :"); in.nextLine();' –