当前位置: 代码迷 >> J2EE >> 初学求解 卖票程序疏失
  详细解决方案

初学求解 卖票程序疏失

热度:49   发布时间:2016-04-22 00:51:59.0
初学求解 卖票程序出错
class Tickets implements Runnable
{
  private int num=100;
  public void run();
  {
  while(true)
  {
  if(num>0)
  {
  System.out.println(Thread.currentThread().getName()+".........."+num--);
  } 
  }
  }
}
class ThreadDemo
{
 public static void main(String [] args)
 {
  Tickets t = new Tickets();
  Thread m1 = new Thread(t);
  Thread m2 = new Thread(t);
  Thread m3 = new Thread(t);
  Thread m4 = new Thread(t);
  m1.start();
  m2.start();
  m3.start();
  m4.start();
 }
}

------解决方案--------------------
两个错误:
1、public void run(); 后面这个分号拿来干啥?删掉!
2、class ThreadDemo 怎么漏了public,没有public的main()函数无法启动。
  相关解决方案