借助static 关键字实现两个窗口交替售票(共二十张票)并输出哪个窗口售票,以及剩余的票数。
public class StaticDemo {
//**
//*两个窗口,交替卖票 ticket = 20;
String name;
static int ticket = 20;
StaticDemo(String name){
this.name = name;
}
void sell() {
//while (ticket = 20)
//{
ticket--;
System.out.println(name+"余票为:"+ticket);
//}
}
public static void main(String[] args) {
// TODO 自动生成的方法存根
StaticDemo demo1 = new StaticDemo("第一个窗口");
StaticDemo demo2 = new StaticDemo("第二个窗口");
while(ticket > 0)
{
demo1.sell();
demo2.sell();
}
}
}
实现结果: