Scanner를 이용해 정수를 입력받기. 에러시 다시 입력받기 위한 프로그램이다. while(true){ try{ System.out.println("정수입력"); n = sc.nextInt(); break; }catch(InputMismatchException e){ sc.next(); System.out.println("error :"+ e.toString()); } } catch문에서 sc.next()를 쓰는 이유? - 정수 이외의 문자를 입력하면 sc.nextInt()에서 에러가 발생하고 키 버퍼(?)에서 값이 빠져나가지 않은 상태가 되며 catch문을 무한 반복하게 된다. 때문에 sc.next()를 사용해 버퍼의 값을 강제로 비워주는 작업이 필요하다.