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

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

}

RgrWalkerAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
CEHJConnect With a Mentor Commented:
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
 
sudhakar_koundinyaCommented:
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
All Courses

From novice to tech pro — start learning today.