创建两个线程分别交替输出奇数和偶数 不输出星号一直输出 用java代码编写
时间: 2023-03-15 18:38:45 浏览: 100
public class ThreadDemo {
public static void main(String[] args) {
new Thread(()->{
for (int i = 1; i <= 100; i+=2) {
System.out.println(i);
}
}).start();
new Thread(()->{
for (int i = 2; i <= 100; i+=2) {
System.out.println(i);
}
}).start();
}
}
阅读全文