Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / September 2005

Tip: Looking for answers? Try searching our database.

Pause a While Statement

Thread view: 
erinash777@hotmail.com - 11 Sep 2005 22:59 GMT
Anyone know how to pause within a while statement?  I have a while
statement that prints over 300 lines of output.  I need for the
statement to count the lines as they are being printed and pause after
20 or 30 lines, prompt the user to press any key, and continue through
the loop.

while (loopCount < intTerminYears * intTerminMonths)
{
dblMonthlyInterestRate = dblBeginBalance * (dblInterestRate / 12);
dblPrinciple = dblPayment - dblMonthlyInterestRate;
dblEndBalance = dblBeginBalance - dblPrinciple;
System.out.println("" + format4.format (dblBeginBalance) + "\t\t" +
format5.format (dblMonthlyInterestRate) + "\t\t" + format6.format
(dblPrinciple) + "\t\t   " + format7.format (dblEndBalance));
loopCount = loopCount + 1;
dblBeginBalance=dblEndBalance;
}
Roedy Green - 12 Sep 2005 04:43 GMT
On 11 Sep 2005 14:59:26 -0700, erinash777@hotmail.com wrote or quoted

>Anyone know how to pause within a while statement?  I have a while
>statement that prints over 300 lines of output.  I need for the
>statement to count the lines as they are being printed and pause after
>20 or 30 lines, prompt the user to press any key, and continue through
>the loop.
you can do a read of a line and have the user hit enter to continue.

see http://mindprod.com/applets/fileio.html
for how to do console i/o.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.

Remi Arntzen - 12 Sep 2005 06:13 GMT
> I need for the
> statement to count the lines as they are being printed and pause after
[quoted text clipped - 7 lines]
> [...]
> }

while (loopCount < [...])
{
 if (loopCount%30 == 0 && loopCount != 0) {
   System.out.println("<prompt/>");
   System.in.read();
 }
[...]
//loopCount = loopCount + 1;
//does not really matter...  i just like it better that way :-)
loopCount++;
[...]
}
erinash777@hotmail.com - 12 Sep 2005 17:03 GMT
I have tried this already.  The problem is, when a user presses the
enter key just once, the program acts as if the user actually presses
the error key twice.  Thanks for the input and any additional help with
this "fix" in getting the program to accept the Enter key only once
would be appreciated.

> > I need for the
> > statement to count the lines as they are being printed and pause after
[quoted text clipped - 20 lines]
> [...]
> }
Gordon Beaton - 12 Sep 2005 18:05 GMT
> I have tried this already.  The problem is, when a user presses the
> enter key just once, the program acts as if the user actually presses
> the error key twice.  Thanks for the input and any additional help with
> this "fix" in getting the program to accept the Enter key only once
> would be appreciated.

InputStream.read() returns each character entered. The Enter key
generates 2 separate characters on "some" platforms.

Use BufferedReader.readLine() instead, which returns once for each
line (regardless of how the end of line is defined on your platform).

/gordon

Signature

[  do not email me copies of your followups  ]
g o r d o n + n e w s @  b a l d e r 1 3 . s e



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.