I'm getting this error java.util.NoSuchElementException from my code below and I can't figure out why. I'm attempting to write a code that reads an integer, a list of words, and a character. The integer signifies how many words are in the list. The output of the program is every word in the list that contains the character at least once.
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
String[] arr = new String[n];
for(int i = 0; i < n; ++i) {
arr[i] = in.next();
}
char ch = in.next().charAt(0); //line that launches the error
for(int i = 0; i < n; ++i) {
if(arr[i].contains(""+ch)) {
System.out.println(arr[i]);
}
}
}