I have spaces being equal to 2. However, I want my else statement to execute when spaces does not equal 2 (whether that's more than 2 or less than 2).
if(difficulty.equalsIgnoreCase("h")) // The only way to make this work (for whatever reason) is to input the numbers twice (ex. "5 5", then underneath, "5 5")
{
if(spaces == 2)
{
while(hidden.contains(word))
{
if(word.charAt(0) == hidden.charAt(spaces1))
{
dash = dash.substring(0, spaces1) + word + dash.substring(spaces1 + 1, dash.length());
}
if(word.charAt(0) == hidden.charAt(spaces2))
{
dash = dash.substring(0, spaces2) + word + dash.substring(spaces2 + 1, dash.length());
}
if(word.charAt(0) == hidden.charAt(spaces1) || (word.charAt(0) == hidden.charAt(spaces2)))
{
rightGuess = true;
System.out.println("Your guess is in the word!");
System.out.println("The updated word is " + dash);
continue game;
}
}
numGuessed = numGuessed - 1;
System.out.println("Your letter was not found in the spaces you provided.");
System.out.println("Guesses Remaining: " + numGuessed);
System.out.println("The updated word is " + dash);
continue game;
}
else //this else statement doesn't execute
{
System.out.println("Your input is invalid. Try again.");
continue game;
}
I've tried labeling else as "else (spaces != 2), but that doesn't execute anything, and if there's no else statement, there's no execution unless the user enters 2 integers. I can't seem to perform an execution for the alternative.
Aucun commentaire:
Enregistrer un commentaire