code: public static String ask(String prompt, String firstChoice, String... choices) 
        throws IOException {
      while (true) {
        LOG.info(prompt);
        StringBuilder responseBuilder = new StringBuilder();
        while (true) {
          int c = System.in.read();
          if (c == -1 || c == '\r' || c == '\n') {
            break;
          }
          responseBuilder.append((char)c);
        }
        String response = responseBuilder.toString();
        if (response.equalsIgnoreCase(firstChoice))
          return firstChoice;
        for (String c : choices) {
          if (response.equalsIgnoreCase(c)) {
            return c;
          }
        }
        LOG.error("I'm sorry, I cannot understand your response.\n");
      }
    }
docs: Display a prompt to the user and get his or her choice.
  
  @param prompt      The prompt to display
  @param default     First choice (will be taken if autoChooseDefault is
  true)
  @param choices     Other choies
  
  @return            The choice that was taken
  @throws IOException