dimanche 19 novembre 2017

Java random words

I am making a hangman game for a class and need to randomly choose from a list of words. My teacher said there is something wrong with my random class statement. Can someone please help?

This is my code:

String words[] = {
        "math",
        "cake",
        "book",
        "holy",
        "life",
        "mood",
        "hook",
        "moon",
        "fair",
        "flex",
        "able",
        "baby",
        "bath",
        "hell",
        "keys",
        "lock",
        "play"
    };
    Random word = new Random();
    int x = word.nextInt(17);
    String wordToGuess = words[x];




Aucun commentaire:

Enregistrer un commentaire