my dog learned polymorphism*
The moose likes Beginning Java and the fly likes Pause Output Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Pause Output" Watch "Pause Output" New topic
Author

Pause Output

Ken Ng
Greenhorn

Joined: Feb 14, 2004
Posts: 26
Hi all,
Wonder if anyone can help me with the following problem,
I have an array which contains for instance 100 elements and i want to print each element line by line.
When the program is run, i want to view a definite number of values, say 20 elements at a time.
* In addition, i may probably want to view any number of values i like at a time.
How shall i achieved that?
Naren Chivukula
Ranch Hand

Joined: Feb 03, 2004
Posts: 577

For pausing the output and to print specified no.of elements it is better to use threads concept and make the output to sleep for the specified time.
[ February 25, 2004: Message edited by: Naren Chivukula ]

Cheers,
Naren
(OCEEJBD6, SCWCD5, SCDJWS, SCJP1.4 and Oracle SQL 1Z0-051)
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Perhaps you want to do a simple "press enter to continue" as follows.


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Ken Ng
Greenhorn

Joined: Feb 14, 2004
Posts: 26
My original intention is to do something similar when using the switch cmd in DOS e.g.
C:\> dir/p
This cmd will list a paragraph of directories in c:\, consecutive listings can be viewed by pressing enter.
I tried the following...

Get the following results
- 0 to 20 is printed line by line
- "Press Enter to continue..." is displayed followed by a prompting
- After Enter key pressed,

38
39
40
Press Enter to continue... <skipped read()>
41
...all the way to 59 (line by line), program ends
21 to 37 missing
Skipped 2nd read() (at j = 40)
Tried other values j = 15~25 * k, but no avail
Pls help!
[ February 25, 2004: Message edited by: Ken Ng ]
[ February 25, 2004: Message edited by: Ken Ng ]
Eddie Vanda
Ranch Hand

Joined: Mar 18, 2003
Posts: 281
Hi Ken,
If you divide your loop count by the number of lines you want printed and then take the modula (remainder), then when that is 0 you should pause it.
e.g,

You might need to adjust that a little because 0 % 20 is also zero, so check at the end of your loop.

Eddie
[ February 25, 2004: Message edited by: Eddie Vanda ]

The nice thing about Standards is that there are so many to choose from!
Ken Ng
Greenhorn

Joined: Feb 14, 2004
Posts: 26

You might need to adjust that a little because 0 % 20 is also zero, so check at the end of your loop.

Eddie
[ February 25, 2004: Message edited by: Eddie Vanda ][/qb]<hr></blockquote>
Hi eddie, thanks for the interest in this topic
I tried your method

but it prints out even elements array[0], array[2]..., is because j is increment by 2 per loop
1st: inside if(..++j...)
2nd: inside for(...;...;j++)
I change the if to get around the 0 and even printing problem,


But the real issue does not lie on the if or read() statement, i think it might have something to do with the way DOS displays information. Otherwise, 2nd execution of read() (at j = 40) wouldn't missed. If u have time, u can try it out and see for yourself.
Still need some help around this area
For now, at least i can get rid of the extra k variable which is not too bad.
[ February 26, 2004: Message edited by: Ken Ng ]
[ February 26, 2004: Message edited by: Ken Ng ]
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
...all the way to 59 (line by line), program ends
21 to 37 missing

I cannot replicate this problem. I just ran your posted code a few times, and each time every number 0 through 59 appears, with "Press enter to continue..." after 20 and 40.
What version of Windows are you using? If you direct the output to a text file, what happens. Note that you can redirect console output in DOS by running a Java application in the following fashion.
java Foo > results.txt
[ February 26, 2004: Message edited by: Dirk Schreckmann ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Pause Output