java.util.scanner - How to restrict user scanner input data type (java)? -


Say, I want the user to input only an integer, but nothing like "bacon" One way to restrict is to have an input for integer (or other data types), so I do not get any errors or input other than integer?

Assume that your scanner name is myScanner:

  public Fixed int checkI input () {{myScanner return.nextInt ()} hold (InputMismatchException e) {myScanner.next (); System.out.println ("Bacon Luff"); Return 0; }}  

And then you can call that method.


Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -