Is it possible to brake out of a scanner string input so it reads an int instead "purposely"? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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"?

10th Jul 2017, 9:58 PM
D_Stark
D_Stark - avatar
1 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).
15th Jul 2017, 6:48 AM
marit vandijk