whats the problem with this hangman?
run the program and see whats the problem... the think that causes the problem are the spaces is the array... code: import java.util.*; public class Class1 { public static void main(String[] args) { System.out.println("Enter a Character/letter:"); String word = "hangman"; char[] charArr = word.toCharArray(); int tries = 20; String blank = ""; for (int i = 0; i < word.length(); i++){ blank = blank + "_ "; } char[] blankCharArr = blank.toCharArray(); System.out.println(blank); System.out.println(""); Scanner scan = new Scanner(System.in); char aTry; while (tries > 0){ aTry = scan.next().charAt(0); for (Character j: charArr){ if(j.equals(aTry)){ int indexOfChar = word.indexOf(aTry); if (blankCharArr[indexOfChar] == '_'){ blankCharArr[indexOfChar] = aTry; }else if (blankCharArr[indexOfChar] == ' ' && blankCharArr.length -1 > indexOfChar){ blankCharArr[indexOfChar +1] = aTry; } System.out.println(String.valueOf(blankCharArr)); break; } } tries++; } if (tries == 0){ System.out.println("You are out of tries!"); }else{ System.out.println("Congrats!"); } } }