title: How can I check user input if it is valid or invalid input?
body: <pre><code>public static void main(String args[]) {
      Scanner scanner = new Scanner(System.in);
      Random random = new Random();
      String word[] = { "apple" };
  
      char wordguess[] = word[random.nextInt(word.length)].toCharArray();
      int totalOfGuesses = wordguess.length;
      char[] userGuess = new char[totalOfGuesses]; // save the users input
  
      System.out.print("Please input your guess : ");
      char input = scanner.nextLine().charAt(0);
  }
  </code></pre>
  
  <p>How can I check user input if it is valid or invalid input?<br>
  then, if it is valid, store it in an array called value<br>
  otherwise, save the character in the array called invalid.<br>
  thank for help  </p>
  
  <p>For example:<br>
  valid:_ _ _ _ _  invalid:_ _ _ _ _<br>
  Please input your guess : a  </p>
  
  <p>For example:<br>
  valid: a _ _ _ _  invalid:_ _ _ _ _<br>
  Please input your guess : a  </p>
  
  <p>For example:<br>
  valid: a _ _ _ _  invalid:b _ _ _ _<br>
  Please input your guess : b  </p>
  
  <p>For example:<br>
  valid: a _ _ _ _  invalid:b _ _ _ _ 
  Please input your guess : b (will not save b again) </p>