I am a newbie to Java and would be very grateful if someone could look into this code snippet and give me a hand.
@SuppressWarnings("unused")
public static void main(String[] args) throws IOException {
File fin = new File("wordList");
FileInputStream fis = new FileInputStream(fin);
BufferedReader br = new BufferedReader(new nputStreamReader(fis));
List<String> wordList = new ArrayList<>();
List<Character> guessedCharacters = new ArrayList<>();
char guessedCharacter;
String line = "";
while ((line = br.readLine()) != null) {
wordList.add(line);
}
br.close();
System.out.println("Welcome to hanged man.");
System.out.println();
for (int i = 0; i < wordList.size(); i++) {
System.out.print("Guess a letter: ");
guessedCharacter = (char) System.in.read();
System.out.println('\n');
}
When I run the code snippet above I get the following output:
Welcome to hanged man.
Guess a letter: d
Guess a letter:
Guess a letter:
My intention is to have the prompt "Guess a letter" appear only once after I enter the first letter.
If I replace "wordList.size()" in the for-loop with any integer larger than three I get the same result.
I hope to hear from someone. Thank you in advance. Marcos