Java Console Prompt promptRequired(String message)

Here you can find the source of promptRequired(String message)

Description

Prompt user for input, requiring non-empty input.

License

Open Source License

Parameter

Parameter Description
message a parameter

Return

a line of user's input

Declaration

public static String promptRequired(String message) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.Scanner;

public class Main {
    private static Scanner in = new Scanner(System.in);

    /**/*from w w w  .j  a  va  2  s. com*/
     * Prompt user for input, requiring non-empty input.
     * @param message
     * @return a line of user's input
     */
    public static String promptRequired(String message) {
        System.out.print(message + ": ");
        String line = in.nextLine().trim();
        return line.equals("") ? promptRequired(message) : line;
    }
}

Related

  1. prompt(String output)
  2. prompt(String prompt)
  3. promptEnterKey()
  4. promptHidden(String message)
  5. promptPressEnterToExit()