#Not sure why nextLine() is using a previous line on top of the one which has just been entered.
7 messages · Page 1 of 1 (latest)
⌛ This post has been reserved for your question.
Hey @fleet rampart! Please use
/closeor theClose Postbutton above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
If Scanner#nextLine reads an empty line after calling a different Scanner#next method, take a look at this StackOverflow post.
maybe something a little more than a link would be great?
could you send whole code in text, so we could analyse it more accurate?
Scanner scanner = new Scanner(System.in);
String userInput = new String();
userInput = scanner.nextLine();
if(modelRecords.isEmpty()){
System.out.print("""
There are no model records. Returning to main menu.
>""");
scanner.nextLine();
returnToMainMenu();
}
if(!userInput.matches("[0-9]+")){
System.out.println("Please only input whole, valid numbers.");
checkInpDelRecord(modelRecords);
}
System.out.println(userInput);
if(Integer.parseInt(userInput) < 1 || Integer.parseInt(userInput) > modelRecords.size()){
System.out.printf("Please input a valid record number between 1-%d.\n", modelRecords.size());
}
else{
return userInput;
}
return "0";
}```
thanks