Java Class BRReadLines

BRReadLines.java 

// Reading a string from console using a BufferedReader. 

Sample Coding 1:

import java.io.*;

class BRReadLines{
 public static void main(String[] args)throws IOException{
  String str;
  BufferedReader br=new BufferedReader(
     new InputStreamReader(System.in));

  System.out.println("Enter lines of text.\n Enter 'stop' to quit.");
  do {
   str=br.readLine();
  System.out.println(str);
    } while (!str.equals("stop"));
   } }
 

Sample Coding 2:

package filehandling1;

import java.io.*;

class BRReadLines {

    public static void main(String args[]) throws IOException {
        // Create a BufferedReader using System.in 
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str;
        System.out.println("Enter lines of text.");
        System.out.println("Enter 'end' to quit.");
        str = br.readLine();
        while (!str.equals("end")) {
            System.out.println(str);
            str = br.readLine();
        }
    }
}
 

Sample Coding 3:

import java.io.*;

class BRReadLines {
  public static void main(String args[]) 
    throws IOException
  {
    // create a BufferedReader using System.in
    BufferedReader br = new BufferedReader(new 
                            InputStreamReader(System.in));
    String str;

    System.out.println("Enter lines of text.");
    System.out.println("Enter 'stop' to quit.");
    do {
      str = br.readLine();
      System.out.println(str);
    } while(!str.equals("stop"));
  }
}

Java Programming

See also
Changing Fahrenheit to Centigrade

Do you have a Java Problem?
Ask It in The Java Forum

Java Books
Java Certification, Programming, JavaBean and Object Oriented Reference Books

Return to : Java Programming Hints and Tips

All the site contents are Copyright © www.erpgreat.com and the content authors. All rights reserved.
All product names are trademarks of their respective companies.
The site www.erpgreat.com is not affiliated with or endorsed by any company listed at this site.
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk.
 The content on this site may not be reproduced or redistributed without the express written permission of
www.erpgreat.com or the content authors.