这样很简单,通过Thread.sleep(),方法控制,我写个列子你看下
public class A
{
public static void main(String[] args) throws InterruptedException
{
Thread t=new B();
t.start();
Thread.sleep(500);
for(int i=0;i<10;i++)
{
System.out.print("a");
Thread.sleep(1000);
}
}
}
class B extends Thread
{
public void run()
{
for(int i=0;i<10;i++)
{
System.out.print("b");
try
{
Thread.sleep(1000);
} catch (InterruptedException e)
{
e.printStackTrace();
}
}
}
}
通过控制sleep()方法内的时间来控制循环打印你要的结果
|