title: why is indexof not working?
body: <p>I have a program for a hangman game and the indexof is not working for me? its on line 30. I have been trying to figure it out but I cannot.if (guessedWord.indexOf(letter) >= 0). I will keep trying to find out what I did wrong</p>
  
  <pre><code>import java.io.PrintStream;
  import java.util.Scanner;
  
  public class Hangman
  {
  public static void main(String[] args)
  {
  String[] words = { "write", "program", "that", "receive", "positive" };
  
  Scanner input = new Scanner(System.in);
  char anotherGame;
  do
  {
  int index = (int)(Math.random() * words.length);
  
  String hiddenWord = words[index];
  StringBuilder guessedWord = new StringBuilder();
  
  for (int i = 0; i &lt; hiddenWord.length(); i++) {
  guessedWord.append('*');
  }
  int numberOfCorrectLettersGuessed = 0; int numberOfMisses = 0;
  
  while (numberOfCorrectLettersGuessed &lt; hiddenWord.length()) {
  System.out.print("(Guess) Enter a letter in word " + guessedWord +
  " &gt; ");
  String s = input.nextLine();
  char letter = s.charAt(0);
  
  if (guessedWord.indexOf(letter) &gt;= 0) {
  System.out.println("\t" + letter + " is already in the word");
  } else if (hiddenWord.indexOf(letter) &lt; 0) {
  System.out.println("\t" + letter + " is not in the word");
  numberOfMisses++;
  } else {
  int k = hiddenWord.indexOf(letter);
  while (k &gt;= 0) {
  guessedWord.setCharAt(k, letter);
  numberOfCorrectLettersGuessed++;
  k = hiddenWord.indexOf(letter, k + 1);
  }
  }
  }
  
  System.out.println("The word is " + hiddenWord + ". You missed " + numberOfMisses +         (numberOfMisses &lt;= 1 ? " time" : " times"));
  
  System.out.print("Do you want to guess for another word? Enter y or n&gt; ");
  anotherGame = input.nextLine().charAt(0);
  }while (anotherGame == 'y');
  }
  }
  </code></pre>