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