import java.util.Scanner; public class ConsoleReader implements AutoCloseable { private Scanner scanner = new Scanner(System.in); public int readInt(String error) { while(true) { String s = scanner.nextLine(); try { return Integer.parseInt(s); } catch(NumberFormatException nfe) { System.out.println(error); } } } public String readLine() { return scanner.nextLine(); } @Override public void close() { scanner.close(); } }