public class ThreadDemo{
public static void main(String[] args) {
Thread1 thread1 = new Thread1();
Thread2 thread2 = new Thread2();
try {
thread1.start();
thread1.join();
/*
* join()的作用:可以简单理解为告诉下面的线程让其先等待,
等当前线程执行完后,再去执行下面的线程
* */
} catch (InterruptedException e) {
e.printStackTrace();
}
thread2.start();
}
}
class Thread1 extends Thread{
public void run() {
for (int i = 65; i <= 90; i++) {
if (i % 5 == 0)
System.out.println();
System.out.print((char) i + " ");
}
}
}
class Thread2 extends Thread{
public void run() {
for (int i = 65; i <= 90; i++) {
if (i%5==0)
System.out.println();
System.out.print(i+" ");
}
}
}
07-14
384
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
11-01
414
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)