Write a hangman game that randomly generates a word andprompts the user to guess one letter at a time, as presented in the sample run.Each letter in the word is displayed as an asterisk. When the user makes a correctguess, the actual letter is then displayed. When the user finishes a word, displaythe number of misses and ask the user whether to continue to play with anotherword. Declare an array to store words, as follows:// Add any words you wish in this arrayString[] words = {"write", "that",...}; (Guess) Enter a letter in word ******* > p↵Enter(Guess) Enter a letter in word p****** > r↵Enter(Guess) Enter a letter in word pr**r** > p↵Enterp is already in the word(Guess) Enter a letter in word pr**r** > o↵Enter(Guess) Enter a letter in word pro*r** > g↵Enter(Guess) Enter a letter in word progr** > n↵Entern is not in the word(Guess) Enter a letter in word progr** > m↵Enter(Guess) Enter a letter in word progr*m > a↵EnterThe word is program. You missed 1 timeDo you want to guess another word? Enter y or n>
Write a hangman game that randomly generates a word and
prompts the user to guess one letter at a time, as presented in the sample run.
Each letter in the word is displayed as an asterisk. When the user makes a correct
guess, the actual letter is then displayed. When the user finishes a word, display
the number of misses and ask the user whether to continue to play with another
word. Declare an array to store words, as follows:
// Add any words you wish in this array
String[] words = {"write", "that",...};
(Guess) Enter a letter in word ******* > p↵Enter
(Guess) Enter a letter in word p****** > r↵Enter
(Guess) Enter a letter in word pr**r** > p↵Enter
p is already in the word
(Guess) Enter a letter in word pr**r** > o↵Enter
(Guess) Enter a letter in word pro*r** > g↵Enter
(Guess) Enter a letter in word progr** > n↵Enter
n is not in the word
(Guess) Enter a letter in word progr** > m↵Enter
(Guess) Enter a letter in word progr*m > a↵Enter
The word is
Do you want to guess another word? Enter y or n>

Step by step
Solved in 3 steps with 1 images









