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 -

c# - Chart control: Design messed Up after clearing and re-adding Y-Values -

javascript - Bootstrap Modal won't close, previously appended to Body using JQuery -