The LinkedList only shows the same output. I am trying to use the last while loop but it does not work. This is a "Duck Duck Goose" problem. I am not supposed to use Indexing.
19 names
public class DuckDuckGoose {
public static void main(String[] args) {
LinkedList<String> linkedlist = new LinkedList<String>();
// add try catch to add list
try {
FileReader fr = new FileReader(...players.txt");
Scanner inFile = new Scanner(fr);
while (inFile.hasNextLine()) {
linkedlist.add(inFile.nextLine());
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
Iterator<String> iterator = linkedlist.iterator();
// checks until the last list
while (!iterator.hasNext()) {
if (iterator.next().equals(getRandomBoolean())) {
iterator.remove();
}
}
System.out.println(linkedlist);
}
public static boolean getRandomBoolean() {
return Math.random() < 10 * 0.5;
}
}