import java.io.Console;
public class ConsoleDemo {
public static void main(String[] args) {
Console cnsl = null;
String name = null;
try{
// creates a console object
cnsl = System.console();
// if console is not null
if (cnsl != null) {
// read line from the user input
name = cnsl.readLine("Name: ");
// prints
System.out.println("Name entered : " + name);
}
}catch(Exception ex){
// if any error occurs
ex.printStackTrace();
}
}
}
jagvllead 0 Newbie Poster
stultuske 1,116 Posting Maven Featured Poster
somjit{} 60 Junior Poster in Training Featured Poster
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
<M/> commented: :) +8
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.