• Post Reply Bookmark Topic Watch Topic
  • New Topic

sleep() method?  RSS feed

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm just now learning the concepts of threads.....I tried to execute this pgm :
class td{
public static void main(String args[]){
Thread t=Thread.currentThread();
System.out.println("current thr " +t);
System.out.println("after name change ");
try{
for(int i=5;i>5;i--){
System.out.println(i);
t.sleep(1000);
}
}catch (InterruptedException e){
System.out.println("main thread interrupted");
}
}
}
But as expected, the pgm had to print the numbers 1,2,3,4 and 5, in an interval of 1 sec between each number, but it didn't print. The output just stopped with the print of "after name change ". Why doesn't that print the numbers??
 
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

for(int i=5;i>5;i--){
System.out.println(i);
t.sleep(1000);
}

Hi,
loop is not coded as expected. you can code it like "for(int i=5;i<=1;i--)".
hope it helps
regds
George
George, We all make mistakes. It will be helpful if we help others rectify their mistakes. I have modified your message to remove inappropriate content.

[This message has been edited by Rahul Mahindrakar (edited January 28, 2001).]
 
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

loop is not coded as expected. you can code it like "for(int i=5;i<=1;i--)". <br />
<br />
might work better.
- Peter
Peter , I have removed content that i feel is inappropriate.

[This message has been edited by Rahul Mahindrakar (edited January 28, 2001).]
 
George Toronto
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh, I am sorry, it is a type error. Thank you for correcting it.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!