Monday, March 12, 2012

How does BufferedReader class works?

     BufferedReader class is used to read/write anything that read/write in our System IO. If you are familiar in "scanf" in turbo C, its alike. In JAVA, before you use BufferedReader you need to call/ import the class to avoid syntax errors in our program.

     import java.io.BufferedReader;
     import java.io.IOException;
     import java.io.InputStreamReader;

    // "java.io.*;" can be use also
     

       public class HowBuffered {

    //be sure to use proper filename
    
      public static void main(String[] args) throws IOException {
             //most methods of IO must have throws IOException
        BufferedReader realmyn=new BufferedReader(new InputStreamReader(System.in));
            //this must be the statement
        
         String name; // declare name as string

         System.out.println("anu pangalan mo?");
         name=realmyn.readLine();
         // the system will read the user's name, any.
         System.out.println("Kumusta ka "+name+"?");
    }
}

OUTPUT:
anu pangalan mo?
user's input kahit anu name:)
Kumusta ka user's input kahit anu name:)?


More examples by request
More lessons to come.
SHARE and LEARN!



No comments:

Post a Comment