Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Pause Output

 
Ken Ng
Greenhorn
Posts: 26
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 577
Java Notepad Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Perhaps you want to do a simple "press enter to continue" as follows.
 
Ken Ng
Greenhorn
Posts: 26
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 281
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Ken Ng
Greenhorn
Posts: 26
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 7023
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
...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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic