Here you can find the source of prompt(String message, String defaults)
Parameter | Description |
---|---|
message | a parameter |
defaults | a parameter |
public static String prompt(String message, String defaults)
//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 .jav a 2 s . c o m * Prompt user for input. * @param message * @return a line of user's input */ public static String prompt(String message) { System.out.print(message + ": "); return in.nextLine().trim(); } /** * Prompt user for input, providing a default input. * @param message * @param defaults * @return a line of user's input */ public static String prompt(String message, String defaults) { System.out.print(message + " [" + defaults + "]: "); String line = in.nextLine().trim(); return line.equals("") ? defaults : line; } }