第一个:
int n = 300;
public void run(){
while(n > 0){
System.out.print(n-- + " ");
try{
Thread.sleep(1000);
}
catch(InterruptedException e){}
}
System.out.print(300);
}
第二个问题不太明白楼主什么意思
int n = 300;
public void run(){
while(n > 0){
System.out.print(n-- + " ");
try{
Thread.sleep(1000);
}
catch(InterruptedException e){}
}
System.out.print(300);
}
第二个问题不太明白楼主什么意思
{
private int start=300;
public void run()
{
for(int i=start;i>=0;i--)
System.out.println(i);
System.out.println(start);
}
public static void main(String[] args)
{
new Thread(new TestThreadExample1()).start();
}
}
public class TestThreadExample2 implements Runnable
{
int start=300;
public void printByeInfo(String info)
{
System.out.println("I am going to stop running at once!,I am "+info);
}
class ChildThread implements Runnable
{
String name;
public ChildThread(String name)
{
this.name = name;
}
public void run()
{
for(int i=0;i<start;i++)
{
try
{
Thread.sleep(10);
}catch(Exception ex)
{
ex.printStackTrace();
}
};
printByeInfo(""+name+" 号子线程");
}
}
public void run()
{
new Thread(new ChildThread(" 1 ")).start();
new Thread(new ChildThread(" 2 ")).start();
new Thread(new ChildThread(" 3 ")).start();
printByeInfo("主线程");
}
public static void main(String[] args)
{
new Thread(new TestThreadExample2()).start();
}
}
300
299
而题的意思是倒计时那样,300过后消失再显示299