多线程 打印ABC,奇偶数

package com.ryx.test.stragy; 打印ABC 奇偶类似 public class ABCTest{public static void main(String args[]){Thread t1 = new Thread(new Test("A"),"A"); Thread t2 = new Thread(new Test("B"),"B"); Thread t3 = new Thread(new Test("C"),"C"); t1.start(); t2.start(); t3.start(); }static class Test implements Runnable{static volatile int i =0; static int value=https://www.it610.com/article/1; String name=null; public Test(String name){this.name =name; }public void run(){ while (value<=300){ if("A".equals(name)&&0==i){ System.out.println(value++ +":A"); i=1; }if("B".equals(name)&&1==i){ System.out.println(value++ +":B"); i=2; } if("C".equals(name)&&2==i){ System.out.println(value++ +":C"); i=0; }}}}}

    推荐阅读