⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xxx.java

📁 多线程是JAVA的难点
💻 JAVA
字号:

public class XXX
{
  static int tickets=100;
  public static void main(String [] args)
  {
     saleone one=new saleone(tickets);
     one.start();
     saletwo two=new saletwo(tickets);
     two.start();
     salethree three=new salethree(tickets);
     three.start();
     salefour four=new salefour(tickets);
     four.start();
  }
}

class saleone extends Thread
{
  int tickets;
  public saleone(int tickets)
  {
     this.tickets=tickets;
  }
  public void run()
  {
     while(true)
     {   
         if(tickets>0&&tickets<=25)
         System.out.println("First Window: "+tickets--);
         if(tickets==0)
         System.exit(0);

     }
  }
}

class saletwo extends Thread
{
  int tickets;
  public saletwo(int tickets)
  {
     this.tickets=tickets;
  }
  public void run()
  {
     while(true)
     {   
         if(tickets>26&&tickets<=50)
         System.out.println("Second Window: "+tickets--);
     }
  }
}

class salethree extends Thread
{
  int tickets;
  public salethree(int tickets)
  {
     this.tickets=tickets;
  }
  public void run()
  {
     while(true)
     {   
         if(tickets>51&&tickets<=75)
         System.out.println("Third Window: "+tickets--);
     }
  }
}

class salefour extends Thread
{
  int tickets;
  public salefour(int tickets)
  {
     this.tickets=tickets;
  }
  public void run()
  {
     while(true)
     {   
         if(tickets>75&&tickets<=100)
         System.out.println("Forth Window: "+tickets--);
     }
  }
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -