package book.javacore.booka;
//多窗口售票问题
class ticket implements Runnable{
private int num = 10;
public void run() {
for(num=10;num>=0;num--){
System.out.println(Thread.currentThread().getName()+";"+num);
}
// while(true){
// if(num>0){
// System.out.println(Thread.currentThread().getName()+";"+num--);
// }
// }
}
}
public class TicketDemo {
public static void main(String[] args) {
ticket t = new ticket();
Thread k1 = new Thread(t);
Thread k2 = new Thread(t);
Thread k3 = new Thread(t);
Thread k4 = new Thread(t);
k1.start();
k2.start();
k3.start();
k4.start();
}
}
-----------------------------------------
这个视频上的售票问题,为什么用for循环和while循环得出的结果不同?
|
|