Console.readLine() has the following syntax.
public String readLine()
In the following code shows how to use Console.readLine() method.
// www . j ava2 s.c om import java.io.Console; public class Main { public static void main(String[] args) throws Exception { Console cnsl = System.console(); if (cnsl != null) { String name = cnsl.readLine("Name: "); System.out.println("Name entered : " + name); } } }
The code above generates the following result.