Is it possible to brake out of a scanner string input so it reads an int instead "purposely"? | Sololearn: Learn to code for FREE!

0

Is it possible to brake out of a scanner string input so it reads an int instead "purposely"?

or no matter what i write will it always be trapped within "these quotations marks"?

7/10/2017 9:58:42 PM

D_Stark

1 Answer

New Answer

0

Not sure what your question is, but Scanner has different methods to read from input, including for instance nextInt() to return an int. Alternatively, you could parse the String to an int using Integer.parseInt(scanner.nextLine()); or Integer.valueOf(scanner.nextLine()); assuming the next line contains an Integer (or handle possible exceptions).