zoukankan      html  css  js  c++  java
  • 模拟爬山

    package cn.climb;
    
    public class ClimbThread implements Runnable{
        private int num;
        private int time;
        
        public ClimbThread(int num, int time) {
            super();
            this.num = num;
            this.time = time;
        }
    
        public ClimbThread() {
            super();
        }
    
        @Override
        public void run() {
            for(int i = 0;i<10;i++) {
                String ss = Thread.currentThread().getName();
                
                if(i ==9) {
                    System.out.println(ss+"到达终点");
                    return;
                }
                System.out.println(ss+"在爬第"+(i+1)+"个100米");
                try {
                    Thread.sleep(time);
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
    
    
            
        }
    
    }
    ****************************************************
    package cn.climb;
    
    public class Main {
        public static void main(String[] args) {
            ClimbThread old = new ClimbThread(10,2000);
            ClimbThread young = new ClimbThread(10,1000);
            Thread oldman = new Thread(old,"老年人");
            Thread youngman = new Thread(young,"年轻人");
            oldman.start();
            youngman.start();
        }
    }

  • 相关阅读:
    20210131
    20210130
    20210129
    20210128
    20210127
    例3-7
    例3-5
    例3-4
    例3-3
    例3-2
  • 原文地址:https://www.cnblogs.com/lev1/p/11311679.html
Copyright © 2011-2022 走看看