写一个程序三个线程分别输出A,B,C, 顺序输出ABC十次,用java实现
1个回答
展开全部
package T;
public class Test {
public static void main(String[] args) {
Thread t1 = new test1();
Thread t2 = new test2();
Thread t3 = new test3();
t1.start();
t2.start();
t3.start();
}
}
class test1 extends Thread {
@Override
public void run() {
super.run();
for (int i = 0; i <= 9; i++) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("A");
}
}
}
class test2 extends Thread {
@Override
public void run() {
super.run();
for (int i = 0; i <= 9; i++) {
try {
Thread.sleep(105);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("B");
}
}
}
class test3 extends Thread {
@Override
public void run() {
super.run();
for (int i = 0; i <= 9; i++) {
try {
Thread.sleep(110);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("C");
}
}
}
public class Test {
public static void main(String[] args) {
Thread t1 = new test1();
Thread t2 = new test2();
Thread t3 = new test3();
t1.start();
t2.start();
t3.start();
}
}
class test1 extends Thread {
@Override
public void run() {
super.run();
for (int i = 0; i <= 9; i++) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("A");
}
}
}
class test2 extends Thread {
@Override
public void run() {
super.run();
for (int i = 0; i <= 9; i++) {
try {
Thread.sleep(105);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("B");
}
}
}
class test3 extends Thread {
@Override
public void run() {
super.run();
for (int i = 0; i <= 9; i++) {
try {
Thread.sleep(110);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("C");
}
}
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询