0

[HELP] Can someone explain me the user input program of java?

I've not understood the user input program of java yet. Can someone explain me this with some solid example?

13th Dec 2017, 1:15 PM
Yuvraj Gaonkhowa
Yuvraj Gaonkhowa - avatar
2 odpowiedzi
0
Using Scanner to read 5 integers in this code: https://code.sololearn.com/cFb2DLNK1xCp/?ref=app They can be entered as 1 2 3 4 5 or 1 2 3 4 5 The Scanner class automatically skips whitespace during it's processing in most methods. Using the second set of data, the nextInt method reads the 1 and end of line characters, verifies 1 makes a legal integer, and returns it as an integer. The next call skips the leading spaces, finds the 2 and end of line, verifies 2 makes a legal integer, and returns it. If the 2 was entered as 2a, nextInt would throw an exception as that would not be an integer. There are methods that return other values. next returns a String. nextDouble returns a double. See this for a complete list: https://docs.oracle.com/javase/7/docs/api/java/util/Scanner.html
13th Dec 2017, 2:08 PM
John Wells
John Wells - avatar
+ 1
Thank you so much for helping me out @JohnWells
13th Dec 2017, 2:14 PM
Yuvraj Gaonkhowa
Yuvraj Gaonkhowa - avatar