Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,987 questions

51,931 answers

573 users

How to read a string from console using readLine() in Java

1 Answer

0 votes
package javaapplication1;

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

public class JavaApplication1 {
 
    public static void main(String[] args) {
 
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
                 
        String s = null;
                 
        System.out.println("Write a Line of Text, '.' to quit");
                 
        try
        {
            while ( (s = br.readLine()) != null)
            {
                    if (s.equals("."))
                        break;
                                       
                    System.out.print("The Line of Text is: "  + s);
                    System.out.println();
            }
                       
            br.close();                    
        }
        catch(Exception e)
        {
              System.out.println(e.getMessage());
        }
     }
}
 
 
/*
 
run:
                    
Write a Line of Text, '.' to quit
java programming
The Line of Text is: java programming
windows
The Line of Text is: windows
android
The Line of Text is: android
web
The Line of Text is: web
.
  
*/

 



answered Mar 17, 2017 by avibootz
edited Mar 17, 2017 by avibootz

Related questions

1 answer 64 views
1 answer 105 views
1 answer 147 views
1 answer 146 views
1 answer 122 views
1 answer 121 views
121 views asked Oct 12, 2022 by avibootz
...