Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Pause in JAVA

 
danesh far
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
How can I make a pause in my program in java?Could you please give me an example.
 
Henry Wong
author
Marshal
Pie
Posts: 21115
78
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think there is a guaranteed way to pause a whole program... but you pause a thread of execution with:

Thread.sleep(2000);

The above code is for a 2 second pause.

Henry
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here in the beginner's forum, I'd guess that a "press any key..." kind of pause is what we're after. Use "System.in.read()" to do that.
 
Joel McNary
Bartender
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
...except that instead of "press any key" it has to be "press RETURN to contine" because the standard console doesn't return anything until RETURN has been pushed.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic