I'd like to exit a while loop when the user inputs the Enter/Return key.
Here's my code:
do
{
//id=sclocal.nextInt();
try{
id=sclocal.nextInt();
}catch(InputMismatchException exception)
{
System.out.println("Invalid input!");
return;
}
if(listperformer.size() <= id || id < 0)
{
System.out.println("Invalid input!");
return;
}
else
{
idlist.add(listperformer.get(id));
}
}while(sclocal.nextLine().length() > 0); //Here I want: *
*If the user does not want to input another id, they input nothing else and press "Enter" to leave this loop.