Java Console Prompt prompt(String message)

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

Description

Prompts the user with a given message and returns their response.

License

Apache License

Parameter

Parameter Description
message The message to show the user, verbatim, with no newline at the end

Return

The user's response to the message. One line of recorded input

Declaration

public static String prompt(String message) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.Scanner;

public class Main {
    /**/*from   w  w w. j av a  2s  .c  o  m*/
     * Scanner instance
     **/
    private static final Scanner scan = new Scanner(System.in);

    /**
     * Prompts the user with a given message and returns their response.
     * The given message is printed verbatim, with no newline, and one line of input is recorded and returned.
     *
     * @param  message   The message to show the user, verbatim, with no newline at the end
     * @return         The user's response to the message. One line of recorded input
     */
    public static String prompt(String message) {
        System.out.print(message + ": ");
        return scan.nextLine();
    }
}

Related

  1. prompt(String message, String defaults)
  2. prompt(String output)
  3. prompt(String prompt)
  4. promptEnterKey()