import java.util.*;
public class UserInput {
public static void main(String[] args) {
String[] words = { "hello", "world" };
Random rand = new Random();
Scanner scanner = new Scanner(System.in);
String choice;
do {
String word = words[rand.nextInt(words.length)];
System.out.println("Guess word");
String guess = scanner.nextLine();
if(word.equals(guess)) {
System.out.println("correct");
} else {
System.out.println("wrong");
// add the list of guessed letters to the settings
// Do you mean to the words array?
words = addGuess(words, guess);
System.out.printf("words = %s%n", Arrays.toString(words));
}
System.out.println("More? \"y\" or any key");
choice = scanner.nextLine();
} while(choice.equals("y"));
scanner.close();
}
private static String[] addGuess(String[] array, String element) {
int len = array.length;
String[] temp = new String[len+1];
System.arraycopy(array, 0, temp, 0, len);
temp[len] = element;
return temp;
}
}