Write a program to allow a user to play the game Hangman. DO NOTUSE AN ARRAY
The program will generate a random number (between 1 and 4581)to pick a word from the file - this is the word you then have toguess.
Note: if the random number you generate is 42, you need the 42ndword - so loop 41 times picking up the word from the file and notdoing anything with it, it is the 42nd you need. Here is how youwill do this:
String word:
for (int k=0; k<41; k++)
{word=scnr.nextLine();
}//end loop and now pick up the word you want
word=scnr.nextLine() //this is the one you want
The user will be allowed to guess a letter as many times as ittakes - but 10 wrong guesses and they lose!!
Eventually either they won or lost. In case they lost print outthe answer.
Code language: Java using JGrasp or NetBeans