0

what is used to enable the scanner class to accept an integer as an input? pls help

https://code.sololearn.com/csLui9ovYy4b/?ref=app

16th Nov 2017, 7:13 AM
delviny amateshe
delviny amateshe - avatar
3 Réponses
+ 3
.nextDouble(); .nextFloat(); .nextLine(); ...
16th Nov 2017, 8:23 AM
Jonas Schröter
Jonas Schröter - avatar
+ 3
Scanner scanner = new Scanner(System.in); int input = scanner.nextInt();
16th Nov 2017, 8:23 AM
Jonas Schröter
Jonas Schröter - avatar
+ 2
You can check how to "read" numerical data from a string in this code snippet https://code.sololearn.com/cgMBmRs5dOgx/?ref=app in your code, you can use your Scanner to read the user input as a string and then use the Integer.parseInt() method to read an integer number from this string. So, in your example (where input is a scanner, and score1 is a variable of type int) that would be score1=Integer.parseInt(input.next())
16th Nov 2017, 8:32 AM
ams