Topic: 怎么样实现让一个数字每隔一秒钟就加1???

  Print this page

1.怎么样实现让一个数字每隔一秒钟就加1??? Copy to clipboard
Posted by: nationalist
Posted on: 2006-09-11 17:09

谢谢了!!!

2.Re:怎么样实现让一个数字每隔一秒钟就加1??? [Re: nationalist] Copy to clipboard
Posted by: vicious
Posted on: 2006-09-12 00:24

public static void main(String[] args){
int i = 0;
while(true){
i++
Thread.sleep(1000);
}
}

3.Re:怎么样实现让一个数字每隔一秒钟就加1??? [Re: vicious] Copy to clipboard
Posted by: nationalist
Posted on: 2006-09-12 12:30

vicious wrote:
public static void main(String[] args){
int i = 0;
while(true){
i++
Thread.sleep(1000);
}
}

谢谢了,回去我研究下Thread.sleep()

4.Re:怎么样实现让一个数字每隔一秒钟就加1??? [Re: vicious] Copy to clipboard
Posted by: jackchengen
Posted on: 2006-09-17 23:54

vicious wrote:
public static void main(String[] args){
int i = 0;
while(true){
i++
Thread.sleep(1000);
}
}

Thread.sleep(Milliseconds)会抛出IterruptedException,所以上面的代码还需要加点东西:
try{
Thread.sleep(1000);
}catch(InterruptedException e){
e.printStackTrace();
}


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923