by Dinesh Thakur Category: Control Structures class is a new class in Java 6 that may be used for reading text from character based console device. The data can be read from the console device provided it is associated with the Java Virtual Machine (JVM).

To determine whether console device is present in the current JVM, we invoke Console() method of System class and if this method returns a Console reference, that means the console device is present in current JVM as shown in following code:

If console device is present in current JVM, we get a console reference which can be used to call the Console class's methods.


Here is the Java Example for Console I/O:


public class ConsoleIO
            public static void main(String[] args)
                        int p,q,r;
                        float a;
                        String val;
                        Console console=System.console();
                        val=console.readLine("Enter first value ");
                        val=console.readLine("enter second value ");
                        val=console.readLine("Enter third value ");
                        System.out.println("Average of three variables is "+a);

About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.C.A, MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.

Related Articles