I am learning java and am making a hangman game but this one line seems to just be ignored and not ran. if i put the same bit of code further up then it is ran, it just isn't ran while its its the while loop. (the "char guess = reader.nextLine().charAt(0);" isn't ran and no input is requested). edit: i have added a reader.nextLine(); after the int input but it still doesnt work.
error:
Exception in thread "main" java.util.NoSuchElementException: No line found
at java.util.Scanner.nextLine(Unknown Source)
at test.Testtt.main(Testtt.java:30)
code:
public class Testtt {
public static void main(String[] args) {
Scanner reader = new Scanner(System.in);
print("Would you like to play singleplayer or multiplayer (s/m)? ");
String mode = reader.nextLine();
print("How many game would you like to play?");
int game_num = reader.nextInt();
reader.nextLine();
int score = 0;
for(int x = 0; x < game_num; x++) {
String word = get_word(mode);
String temp = get_temp(word);
int lives = 6;
String[] guesses = new String[26];
while(lives > 0) {
print("Enter letter");
char guess = reader.nextLine().charAt(0);
temp = update_temp(temp, word, guess);
if(win_check(temp, word)) {
score = score + 1;
break;
}
else {
lives = lives - 1;
display(lives);
}
}
}
}