public class ThreadDemo01 implements Runnable { private static String winner; public void run() { for (int i = 0; i <= 100; i++) { Boolean hi = aaa(i); if (hi) { break; } System.out.println(Thread.currentThread().getName() + "跑了" + i++ + "步"); } } public Boolean aaa(int step){ if (winner!=null){ return true; }{ if(step>=100){ winner=Thread.currentThread().getName(); System.out.println("胜利者是:"+winner); return true;} }return false; } public static void main(String[] args) { ThreadDemo01 demo01 = new ThreadDemo01(); new Thread(demo01,"乌龟").start(); new Thread(demo01,"兔子").start(); } }
标签:赛跑,龟兔,Thread,winner,demo01,ThreadDemo01,new,public From: https://www.cnblogs.com/guojianglong/p/17125782.html