• Post Reply Bookmark Topic Watch Topic
  • New Topic

printing to stdout  RSS feed

 
Spencer J Lee
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I'm trying to write a thread that loops and prints a character from the following array { '|', '/', '-', '|', '/', '-' }. The thing is, I want to print it so that the next character replaces the last drawn character to create the affect of a spinning object.
Unfortunately, I can't seem to figure out how to write to the same location over and over again (instead of advancing to the next character location.)
Any ideas?
Thanks!
Spencer
 
Carlos Failde
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You want a carriage return "\r":
System.out.print("\r" + nextcharacter);
 
Spencer J Lee
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Carriage returns seems to be advancing me to the next line (I'm on a Windows machine).

So I see:
...
\
|
/
-
...

 
Joel McNary
Bartender
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try using a backspace:

I've tested this on my XP box and it works fine. To control the speed of the spin, adjust the sleep on the thread as needed.
 
Spencer J Lee
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
great idea. thanks!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!