0

Why in java you have to give a space input btw int input and Line input?

when we have to take input from scanner , than we have to take a blank input BTW an Int input and Line input. I want to know why we have to add that blank input? for example: Scanner input = new Scanner(System.in); int a; String name; a = input.nextInt(); input.nextLine(); name =input.nextLine(); So ,why we need that input.nextLine(); BTW the input of a and name.

28th Feb 2017, 8:23 PM
VISHAL SINGH RAJPUT
VISHAL SINGH RAJPUT - avatar
2 Answers
+ 1
In Sololearn,the input box says "Separate multiple inputs by multiple lines". Hence users write there next input (in example, its name) in next line. So if we dont use input.nextLine(); then the name will get null value(as there is no value after user's first input (in example its a))
28th Feb 2017, 9:04 PM
Meharban Singh
Meharban Singh - avatar
0
but it is not applicable only on sololearn
28th Feb 2017, 10:13 PM
VISHAL SINGH RAJPUT
VISHAL SINGH RAJPUT - avatar