Turn Desktop View Off
by Dinesh Thakur

The java.io package contains stream classes that support for reading and writing. To use these stream classes, we import the java.io package. For reading characters, we prefer Reader class and we use subclass BufferedReader to read data.

The System class in the language package represents the keyboard, or standard input stream. This member variable in system class is called in and that are the instance of the InputStream class. These variable are useful for reading from the keyboard. The System.in object is used to read user input from the keyboard. For reading data, read()/readLine() method is called. Then, by using Integer.parseInt() method, the data is converted from string to integer.

 

Here is the Java Example for the program Java.io.Reader.read() Method :

 

import java.io.*;

class AreaofRectangle

{

            public static void main (String args[])

            throws IOException

            {

                        BufferedReader k=new BufferedReader(new inputStreamReader

                                    (System.in));

                        String h;

                        int l,b,a;

                        System.out.println("Enter lenght ");

                        h=k.readLine();

                        l=Integer.parseInt(h);

                        a=l*b;

                        System.out.println("Area of Rectangle is "+a);

            }

}

 

One Another Java Example we can See.

import java.io.*;

class AverageofThreeVariables

{

            public static void main (String args[] )

            throws IOException

            {

                        BufferedReader k=new BufferedReader(new InputStreamReader

                                    (System.in));

                        String h;

                        int p,q,r;

                        float a;

                        System.out.print1n("Enter first value ");

                        h=k.raedLine( );

                        p=Integer.parseInt(h);

                        System.out.print1n("Enter second value ");

                        h=k.raedLine( );

                        q=Integer.parseInt(h);

                        System.out.print1n("enter third value ");

                        h=k.raedLine( );

                        r=Integer.parseInt(h);

                        a=(float)(p+q+r)/3;

                        System.out.print1n("Average of three variables is "+a);

            }

}