zoukankan      html  css  js  c++  java
  • 练习四

    package zuoYe03;
    
    public class Sickness {
    
        public static void main(String[] args) {
    
            // 特需房
            Thread t2 = new Thread("特需号") {
    
                public void run() {
                    int i;
                    for (i = 1; i <= 10; i++) {
                        System.out.println(Thread.currentThread().getName() + " : " + i + "号病人在看病!");
    
                        try {
                            Thread.sleep(1000);
                        } catch (InterruptedException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                    }
    
                    if (i > 10) {
                        System.out.println("特需房一天看病次数已满,不能再看病!");
                    }
    
                }
            };
            // 普通号
            Thread t1 = new Thread("普通号") {
    
                public void run() {
    
                    int i;
                    for (i = 1; i <= 50; i++) {
                        System.out.println(Thread.currentThread().getName() + " : " + i + "号病人在看病!");
    
                        try {
                            Thread.sleep(500);
                        } catch (InterruptedException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                        if (i == 10) {
    
                            try {
                                t2.join();
                            } catch (InterruptedException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            }
                        }
                    }
    
                    if (i > 50) {
                        System.out.println("普通房一天看病次数已满,不能再看病!");
                    }
                }
    
            };
    
            t1.start();
            t2.start();
        }
    
    }

  • 相关阅读:
    QQ列表展示
    拖动条SeekBar
    信息提示框、对话框
    键盘事件、触摸事件
    时间日期事件处理,长按事件
    图片切换示例
    索引值的应用
    this的应用
    自定义属性应用1
    自定义属性应用
  • 原文地址:https://www.cnblogs.com/bichen-01/p/11309115.html
Copyright © 2011-2022 走看看