Search
 
SCRIPT & CODE EXAMPLE
 

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();
Comment

PREVIOUS NEXT
Code Example
Java :: java thread class sleep 
Java :: who created java 
Java :: what method is use for getting the index position of a character of a string in java 
Java :: java how to get all threads 
Java :: java thread dump 
Java :: days between two dates android 
Java :: modal css react 
Java :: java gridpane background color 
Java :: split string regex java 
Java :: sqlite java gradle 
Java :: how to print an array in java 
Java :: check GPS is on android 
Java :: check if sqlexception is duplicate entry java 
Java :: java download image file 
Java :: string programs in java 
Java :: how to assert that an exception is thrown java 
Java :: find minimum in rotated sorted array 
Java :: list files in directory java 
Java :: navigate to another activity in android 
Java :: terminate a frame java 
Java :: fill two dimensional array rows by rows java 
Java :: hide element selenium 
Java :: arraylist to array java 
Java :: java string to double comma 
Java :: addall java 
Java :: binary to decimal in java program 
Java :: how to check if notification is showing in android 
Java :: java get number of months between two dates 
Java :: declare variables java 
Java :: java constructor overloading 
ADD CONTENT
Topic
Content
Source link
Name
8+7 =