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
232 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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

728 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now