编写一个多线程的程序一个线程输出20次你的学号,另一个输出20次你的姓名Java代码
时间: 2024-03-10 14:46:34 浏览: 62
多线程编程实例Java代码
```java
public class MultiThreadDemo {
public static void main(String[] args) {
Thread t1 = new Thread(new StudentIdThread());
Thread t2 = new Thread(new StudentNameThread());
t1.start();
t2.start();
}
}
class StudentIdThread implements Runnable {
@Override
public void run() {
for (int i = 0; i < 20; i++) {
System.out.println("My student id is 2021000000000X.");
}
}
}
class StudentNameThread implements Runnable {
@Override
public void run() {
for (int i = 0; i < 20; i++) {
System.out.println("My name is John Smith.");
}
}
}
```
阅读全文