欢迎光临散文网 会员登陆 & 注册

2年大厂经验,面试还是太紧张,90%的人不会写

2023-07-04 20:33 作者:孤独的游荡  | 我要投稿
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();
    }
}

海哥,看看这个怎么样

2年大厂经验,面试还是太紧张,90%的人不会写的评论 (共 条)

分享到微博请遵守国家法律