Home Tutorial Java Corejava How to read from the console

 
 

Share on Google+Share on Google+
How to read from the console
Posted on: April 10, 2010 at 12:00 AM
Advertisement
The tutorial demonstrate the use of Scanner Class.

Description:

Scanner was introduced in jdk 1.5. This class help in taking the input from the console. Here in this sample program it will take one word input from the console and display it.

Code:

import java.util.Scanner;
import java.io.Console;

public class ConsoleExample {
  public static void main(String args[]) {
    Console cons;
    cons = System.console();
    Scanner sc = new Scanner(cons.reader());
    System.out.println(sc.next());
  }
}

Output:

How to read password from the console
This tutorial demonstrate how to read password without showing it on the console
 
How to read and display password from the console
This tutorial demonstrate how to read and display password from the console.
 
Advertisement

Related Tags for How to read from the console:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: April 10, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com