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();
        }
    
    }

  • 相关阅读:
    最小的K个数
    堆排序
    归并排序
    希尔排序
    快速排序
    二分查找
    数组中出现次数超过一半的数字
    包含min函数的栈
    栈的压入、弹出序列
    中缀表达式转后缀表达式
  • 原文地址:https://www.cnblogs.com/bichen-01/p/11309115.html
Copyright © 2011-2022 走看看