I'm wondering how to get input without a line break.
Here's what I made. It gets input all right, but there is a line break without any clear (to me) cause.
Thanks in advance.Code:int GetIntegerInput(String prompt, int min, int max) { boolean valid; String answer = null; int i=0; do { valid=true; System.out.print(prompt+": "); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); try { answer = br.readLine(); } catch (IOException ioe) { System.out.println("IO error trying to read answer!"); System.exit(1); } try { i = Integer.parseInt(answer); } catch (java.lang.Exception ex) { System.out.print("That is not a valid number. "); valid=false; } if (valid) { if (i<min) System.out.print("That is too low. "); else if (i>max) System.out.print("That is too high. "); } } while (!valid || i<min || i>max); return Integer.parseInt(answer); }


Reply With Quote


Bookmarks