Hello Daniweb,
I just created a small program that generates a random integer between a given range then asks the user to guess the number, giving hints like "Too high" or "Too low" along the way until they guess the correct number. I have it all working smoothly, except when the user finishes, they're asked if they wanna play again. And I have that in this method:
private static void playAgain() {
System.out.print("\nPlay again? (Y/N)");
String userResponse = userInput.next().toUpperCase();
char userContinue = userResponse.charAt(0);
if (userContinue == 'Y') {
// User wants to play again, start over
theGuessingGame();
} else if (userContinue == 'N') {
// User doesn't want to play again. Display a goodbye message
System.out.println("Thanks for playing. Goodbye!");
} else {
// If any invalid characters are entered, repeat the play again question
System.out.println("Invalid response. Please try again");
playAgain();
}
}
Now correct me if I'm wrong, but I think by using playAgain() within itself, I'm stacking the same method on top of the other one am I not? Alternatives to something like this?