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
Post a Comment