so I'm working on making a simple hangman game on Java. The computer should choose a random word from a set of words :
public void setWords() {
words[0] = "notions";
words[1] = "measure";
words[2] = "product";
words[3] = "foliage";
words[4] = "garbage";
words[5] = "minutes";
words[6] = "chowder";
words[7] = "recital";
words[8] = "concoct";
words[9] = "brownie";
}
I'm trying to write the code to generate a random word when the player plays: I have this as a starter:
public class Hangman {
private int numwords = 10;
private String[] words = new String[numwords];
private String gameWord;
private String dispWord = "-------";
private char[] dispArr = dispWord.toCharArray();
private static void main(String[] args) {
System.out.println("Welcome to Hangman!:");
Random rand= new Random();
char c = rand.nextChar(setWords);
}
Could you please help with the syntax of choosing a random word using the selectGameWord() method? Thank you!