So I added the yes or no statement prints out but it doesn't allow the user to type it in. How do I fix that and can I nest a while loop inside a do-while loop?
import java.util.Scanner;
import java.util.Random;
public class HiLo {
public static void main(String[] args) {
Random random = new Random();
Scanner input = new Scanner(System.in);
final int MAX = 100;
int answer = random.nextInt(MAX) + 1;
int guess = -1;
int numberOfGuesses = 0;
String cont;
System.out.println("Guess a number between 1 and " + MAX + ": ");
do {
while (guess != answer) {
numberOfGuesses++;
guess = input.nextInt();
if (guess == 101) {
break;
} else if (guess > answer) {
System.out.println("Too High");
System.out.println("\nGuess again ");
} else if (guess < answer) {
System.out.println("Too Low");
System.out.println("\nGuess again: ");
} else {
System.out.println("Correct! The number was " + answer + ".");
System.out.println("It took you " + numberOfGuesses + " guesses.");
}
}
System.out.println("\nWould you like to play again (yes/no)?");
cont = input.nextLine();
} while (cont.equals("yes");
input.close();
}
}