My code for linked lists practice doesn't want to work
So I'm getting the error Java.Util.NoSuchElementException. even though I'm adding the word to the words linkedlists, it thinks theres nothing in that position. Here is the code, can someone tell me what the problem is import java.util.LinkedList; import java.util.Scanner; public class Main { public static void main(String[ ] args) { Scanner scanner = new Scanner(System.in); LinkedList<String> words = new LinkedList<String>(); while(words.size()<5) { String word = scanner.nextLine(); //add the word to LinkedList if(word.length()>4) { words.add(word); } } System.out.println(words); } }