java - How do I get a random word from a string? -
i want create hangman game in java, i'm unsure on how set whole thing up. working on system more letters have, have less chance of appearing on hangman puzzle.
    import java.ultil.scanner;     public class hangman {       public static void main(string[]args); // let's try main?       scr = newscanner(system.in); // used keyboard input       string words = "hi:bye:hello:cheese:puppies";       int length = words.length();       }     }   how can random word variable, "words", , calculate it's length?
please keep in mind, i'm not best @ coding java.
this answers part picking random word , finding length.
string words = "hi:bye:hello:cheese:puppies"; string[] wordsasarray = words.split(":");  int index = new random().nextint(wordsasarray.length);  string randomword = wordsasarray[index]; system.out.println("random word: '" + randomword + "'. of length: " + randomword.length());      
Comments
Post a Comment