This program runs but does not execute this part of the code how I want it to. When I take out what is posted below the program works fine but when I leave it in the program ends after the first letter is entered..
I want the array guesshold to hold the guesses from the user and in this part i have posted below compare the input with everything else that has been entered to see if it has been previously entered. if you want to give any other input on other parts please feel free i am still a beginner!
/*
for(int counter = 0; counter <= 10; counter++)
{
if(guesshold[counter +1 ].equals(guess1))
{
System.out.println("You have already guessed that letter");
}
*/
import java.lang.*; import java.util.*; import java.io.*; public class Program { /** * This is the main entry point for the application */ static Scanner console = new Scanner(System.in); public static void main(String args[]) { System.out.println("Welcome to Hangman!"); System.out.println(); System.out.println("The word is: _ _ _ _ "); // the word is cave String correctguess = "_ _ _ _"; String cave = "cave"; boolean z = false; String replace1 = "1234"; int i = 0; do { int x = 0; int y = 0; System.out.println("Please enter your one letter guess"); String guess1 = console.next(); guess1 = guess1.toLowerCase(); String guesshold[] = new String[11]; guesshold[x] = guess1; if(guess1.equals("c")) { System.out.println("Nice " +guess1+ " is a correct letter!"); replace1 = replace1.replace('1' , 'c'); } else if(guess1.equals("a")) { System.out.println("Nice " +guess1+ " is a correct letter!"); replace1 = replace1.replace('2' , 'a'); } else if(guess1.equals("v")) { System.out.println("Nice " +guess1+ " is a correct letter!"); replace1 = replace1.replace('3' , 'v'); } else if(guess1.equals("e")) { System.out.println("Nice " +guess1+ " is a correct letter!"); replace1 = replace1.replace('4' , 'e'); } else { String wrong1 = "XXXXXXX"; wrong1 = wrong1.substring(0,i); System.out.println("Wrong X" +wrong1); int wronglength = wrong1.length(); i++; if(wronglength == 7) { z = true; } } if(replace1.equals(cave)) { z = true; System.out.println("You WON the guessed the correct letters in the word CAVE"); } for(int counter = 0; counter <= 10; counter++) { if(guesshold[counter +1 ].equals(guess1)) { System.out.println("You have already guessed that letter"); } } }while(z == false); }//ends main method }//ends class