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

📄 例三.txt

📁 Java大学实用教程 耿祥义编著 课件 PPT
💻 TXT
字号:
class Left extends Thread
{
    int n=0;
    public void run()
    {   
        while(true)
         {
            n++;
            System.out.printf("\n%s","我在左面写字");
            try
            {
                 sleep((int)(Math.random()*100)+100);
            }
          catch(InterruptedException e)
            {
            }
         }
    }
}
class Right extends Thread
{
    int n=0;
    public void run()
    {   
        while(true)
         {
            n++;
            System.out.printf("\n%40s","我在右面写字");
            try
            {
                 sleep((int)(Math.random()*100)+100);
            }
          catch(InterruptedException e)
            {
            }
         }
    }
}
class Example
{
    public static void main(String args[ ])
    {
         Left left=new Left();
         Right right=new Right();
         left.start();
         right.start();
         while(true)
         {
             if(left.n==8||right.n==8)
                 System.exit(0);
         }  
    }
}

⌨️ 快捷键说明

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