The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
February 2002

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

thanks

Posted by Saguaro on February 21, 2002 at 12:02 AM

> Have a do..while loop that loops until the user enters a blank line. Have an integer variable that counts the number of lines. Here is an example:
>


> System.out.println("Enter the lines of text. Enter an empty line to end.");
> int numLines = 0;
> do {
> line=SavitchIn.readLine();
> if (!(line.equals("")) {
> numLines++;
> }
> } while (!(line.equals(""));
>

> Also, if you wanted to keep the user input, everytime you call the readLine method, add the result of that method to the end of the variable line (assuming line is a string), like so:
>

> line = line + SavitchIn.readLine();
> // I think line =+ SavitchIn.readLine(); will work as well, but
> // I'm not entirely sure
>

> Hope this helps.
> Hiran

> > I've started java like two weeks ago and there is a part of a program that I am stuck on, I'm supposed to make part of the program do this:
> > Enter the lines of text. Enter an empty line to end.
> > hello
> > i am here

> > number of lines:2

> > so far all I have is:
> > System.out.println("Enter the lines of text. Enter an empty line to end.");
> > line=SavitchIn.readLine();

> > Can you guys help me on what to do next? I don't know how to make the program accept multiple lines and count the number of lines made. Thanks a lot.





Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us