Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

java scanner string nextline after nextint

//The problem is with the input.nextInt() method - it only reads the int value. So when you continue reading with input.nextLine() you receive the "
" Enter key. So to skip this you have to add the input.nextLine(). Hope this should be clear now.

//Try it like that:

System.out.print("Insert a number: ");
int number = input.nextInt();
input.nextLine(); // This line you have to add (It consumes the 
 character)
System.out.print("Text1: ");
String text1 = input.nextLine();
System.out.print("Text2: ");
String text2 = input.nextLine();
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #java #scanner #string #nextline #nextint
ADD COMMENT
Topic
Name
1+8 =