0
NextLine();
Choice = Scanner.nextInt(); Scanner.nextLine(); What does that mean?
5 Answers
+ 4
reads your keyboard input whether string an integer
nextInt() > use for numbers
nextLine() > use for strings
+ 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.
+ 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*/
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.
0
okay but they came after each others without and space between them?