2年大廠經(jīng)驗(yàn),面試還是太緊張,90%的人不會(huì)寫

import java.util.concurrent.atomic.AtomicInteger; public class Main { public static void main(String[] args) { AtomicInteger count = new AtomicInteger(1); Thread thread1 = new Thread() { @Override public void run() { while (count.get() <= 100) { while (count.get() % 2 == 1 && count.get() <= 100) { System.out.println(count.get()+"a"); count.incrementAndGet(); } } } }; Thread thread2 = new Thread() { @Override public void run() { while (count.get() <= 100) { while (count.get() % 2 == 0 && count.get() <= 100) { System.out.println(count.get()+"b"); count.incrementAndGet(); } } } }; thread1.start(); thread2.start(); } }
海哥,看看這個(gè)怎么樣
標(biāo)簽: