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
237 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
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:

696 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