我想写一个计时器类,每秒计数到0,但似乎计数太快了。我究竟做错了什么?
public class Eieruhr {
private int x;
public Eieruhr (int x){
this.x = x;
}
public static void main(String[] args){
Eieruhr eu = new Eieruhr(10);
eu.start();
}
public void start(){
for(int i = 0; i <= x; x--){
long s = System.nanoTime();
while( ((System.nanoTime() - s) / 100000000) < x);
System.out.println("tick - " + x);
}
}
}
阿晨1998
相关分类