0

NextLine();

Choice = Scanner.nextInt(); Scanner.nextLine(); What does that mean?

27th Sep 2017, 7:10 PM
Hmmam Babe khuoja
Hmmam Babe khuoja - avatar
5 Answers
+ 4
reads your keyboard input whether string an integer nextInt() > use for numbers nextLine() > use for strings
27th Sep 2017, 7:32 PM
D_Stark
D_Stark - avatar
+ 3
nextLine() take the ENTIRE line of string input, rather than just the first word of the string. If you used next(), it would take the first word of the string.
27th Sep 2017, 7:35 PM
AgentSmith
+ 2
/*below is all you need to use scanner with string and int*/ import java.util.Scanner; //after main Scanner scn = new Scanner(System.in); //this space is ignored String x = scn.nextLine(); /*< or use "int x = nextInt()" for int*/ //this space is ignored If(x.equalsIgnoreCase("hello")/*< here use somthing like "x==20" for int*/{System.out.println("hey");} /*dont look to much into spaces between your line of code this is called white space and is ignored unless you create white space inside a string is dosent matter*/
27th Sep 2017, 10:09 PM
D_Stark
D_Stark - avatar
0
nextInt skips over white space to find the next integer storing it in choice. It will throw an exception when it finds something other than a number. nextLine returns a string containing everything left on the line, after finding the integer.
27th Sep 2017, 7:37 PM
John Wells
John Wells - avatar
0
okay but they came after each others without and space between them?
27th Sep 2017, 9:58 PM
Hmmam Babe khuoja
Hmmam Babe khuoja - avatar