首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2EE开发 >

初学求解 卖票程序疏失

2012-09-06 
初学求解 卖票程序出错class Tickets implements Runnable{private int num100publicvoid run(){while(

初学求解 卖票程序出错
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()函数无法启动。

热点排行