[Logo]
Forums Register Login
sleep() method?
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??
 


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).]
 


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).]
Oh, I am sorry, it is a type error. Thank you for correcting it.
The only taste of success some people get is to take a bite out of you. Or this tiny ad:
Rocket Oven Kickstarter - from the trailboss
https://coderanch.com/t/695773/Rocket-Oven-Kickstarter-trailboss


This thread has been viewed 1125 times.

All times above are in ranch (not your local) time.
The current ranch time is
Jul 21, 2018 09:47:30.