threaddem.java
来自「java关于线程的一些实例」· Java 代码 · 共 36 行
JAVA
36 行
public class ThreadDem {
public static void main(String[] args) {
Lefthand left;
Righthand right;
left=new Lefthand();
right=new Righthand();
left.start();
right.start();
}
}
class Lefthand extends Thread{
public void run(){
for(int i=1;i<=5;i++){
System.out.print("a");
try{
sleep(500);
}catch(InterruptedException e){}
}
}
}
class Righthand extends Thread{
public void run(){
for(int i=1;i<=5;i++){
System.out.print("b");
try{
sleep(300);
}catch(InterruptedException e){}
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?