Solved

public static String readLine().........Just a few lines of code that are still giving me problems.  Could someone explain these to me?

Posted on 2004-09-08
2
235 Views
Last Modified: 2010-03-31
public static String readLine()...........................Reads it Character by Character from Standard input using Systme.in.read() method
{
StringBuffer sb=new StringBuffer();.................(What is this doing?)
try

{

while(true)

{

char c=(char)System.in.read();

if(c=='\r'||c=='\n' || c==-1 || c==255)...........this line checks for the EOF or newline.

{
break; .......................................This is telling it to go to the end of the program?
}
sb.append(c);..........sb.append(c)  stores the characters

}
}
catch(Exception ex).........................Not sure about this one

{

}

return sb.toString();.....................Also not sure about

}

0
Comment
Question by:RgrWalker
2 Comments
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 12009946
I sugget u to close this question.

You can get answer directly from ur original question

This is just unnecessary to ask same question again for some extra ponts
Regards
Sudhakar
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 125 total points
ID: 12009948
Not sure why you're *still* posting separate qs about this, but here goes:


>>StringBuffer sb=new StringBuffer();.................(What is this doing?)

creates StringBuffer to store input read

>>break; .......................................This is telling it to go to the end of the program?

No. It's telling it to stop reading input

>>catch(Exception ex).........................Not sure about this one

Catch (and ignore) any exceptions

>>return sb.toString();.....................Also not sure about

Return the buffer filled with input as a String
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
V.simple question about Android packages and libraries 1 29
Facing this issue for maven proxy setting 2 20
Problem to Alipay 10 43
Java syntax, or is it Selenium 6 30
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will learn how to implement Singleton Design Pattern in Java.

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question