• Post Reply Bookmark Topic Watch Topic
  • New Topic

Little text editor never gets terminated, what�s wrong?  RSS feed

 
Ellen Zhao
Ranch Hand
Posts: 581
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am implementing a program that asks the user to enter lines of text. After each line the program echos the line to the terminal. The program should finish when the user enters a line that contains the characters //done (use a sentinel-controlled loop and the equals() method of class String.) When it runs, the output on the screen should be exactly the same as what the user inputs. for example, if I run:
C:\java TextEdit
A WORD is dead
When it is said,
Some say.
I say it just
Begins to live
That day.
//done
the output on the screen should be:
A WORD is dead
When it is said,
Some say.
I say it just
Begins to live
That day.
//done
The code I wrote is as below:

It never terminates as I expected. Anyone could tell how to correct the mistake? Thank you very much in advance.

Regards,
Ellen
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ellen,
This does the trick. As they say: "finding out why is left as an exercise for the student "

-Barry
PS For someone starting out with programming in Java I would highly recommend the CattleDrive (with nit removal treatment) here on JavaRanch. It will pay off in your later career, that's for certain.
PS Apologize for large amount of edits
[ December 31, 2002: Message edited by: Barry Gaunt ]
 
Ellen Zhao
Ranch Hand
Posts: 581
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Barry,
Thank you very much for the modification.
Yeah, the cattle drive! I did part ( the entire section one ) of it and it really helps. When I was a freshman, I knew only how to answer the questions in exams but could not really code in Java ( The " Hello world! " class was an exception ), after had driven several cattle in javaRanch, I got my hands dirty with java and things began turning better. I love javaRanch! Some time ago I tried to do the DaysOld assignment, downloaded that package (com.javaranch.common.* ) but unfortunately could never got the package work. I configured the system environment, put the package to where it should be, but...the compiler never found it. Then I stopped there and currently doing some exercises listed in this thread
Thank you again for your kind suggestion.

Regards,
Ellen
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!