I am attempting to write some code that analyzes several pieces of text, but I found an issue with the scanner method. Here is my relevant code:
public static void getInput(Scanner key) {
//This method takes the input of the user and makes it usable, controls all other methods, and prints findings
System.out.print("\nHow many pieces of text do you want to analyze? ");
int textNumb = key.nextInt();
for( int i = 1; i <= textNumb; i++) {
System.out.print("\nPlease enter text sample number " + i + ": ");
key.nextLine();
String textInput = key.nextLine();
System.out.print("text has been received\n"); //this does not print after first round
int sentences = getSentences(textInput);
int words = getWords(textInput);
int syllables = countSyllables(textInput);
printResults(sentences,words,syllables,textInput);
}
}
After the first round of the for loop, the scanner gets stuck and the program pauses completely. If I hit enter again after entering my text after the first round, none of the text actually gets processed by the rest of the methods. What can I do to fix this without closing and re-opening the scanner? Thank you.