zoukankan      html  css  js  c++  java
  • 【0805作业】模拟多人爬山

     1 package mountain;
     2 /**
     3  * 属性:爬100米时长(time) 多少个100米(num);
     4  * 线程休眠模拟爬山延时
     5  * @author L
     6  *
     7  */
     8 public class ClimbThread implements Runnable{
     9     
    10     private int time;
    11     private int num=10;
    12     
    13     public   ClimbThread(int time) {
    14         // TODO Auto-generated method stub
    15         this.time=time;
    16     }
    17     @Override
    18     public void run() {
    19         // TODO Auto-generated method stub
    20         for(int i=num-1;i>=0;i--) {//最高1000米
    21             Thread t=Thread.currentThread();
    22             System.out.println(Thread.currentThread().getName()+"爬完100米");
    23             if(i==0) {
    24                 System.out.println(Thread.currentThread().getName()+"到达终点");
    25                 break;
    26             }
    27             
    28         try {
    29             Thread.sleep(time);
    30         } catch (InterruptedException e) {
    31             // TODO Auto-generated catch block
    32             e.printStackTrace();
    33         }
    34         
    35         }
    36     }
    37 
    38 }
     1 package mountain;
     2 
     3 public class Test {
     4     public static void main(String[] args) {
     5         ClimbThread ct=new ClimbThread(1000);
     6         ClimbThread ct2=new ClimbThread(2000);
     7         Thread young=new Thread(ct,"年轻人");
     8         Thread old =new Thread(ct2,"老年人");
     9         
    10         young.start();
    11         old.start();
    12     }
    13 }

  • 相关阅读:
    Vue收集表单数据
    vcloak、vonce、vpre
    自定义指令总结
    vhtml指令
    Vue模板语法
    vtext指令与插值语法的区别
    Vue过滤器
    sharepoint获取文件的ICON
    Sharepoint中添加/编辑/删除Webpart的几种方法
    [转]客户端input file控件,C#多文件上传
  • 原文地址:https://www.cnblogs.com/yanglanlan/p/11304248.html
Copyright © 2011-2022 走看看