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
236 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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
Java: The Public Class Main 4 45
Eclipse with various Java releases 7 48
Netbeans and org.apache.commons.lang3 issue 3 26
Java List 4 41
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…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
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:

733 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