编写小程序实现 Runnable 接口,通过多线程实现在小程序窗口中不断的显示 自然数:从 1 到 100。
public class NumberThreadTest {
public static void main(String[] args) {
NumberThread nt=new NumberThread();
Thread t=new Thread(nt);
t.start();
}
}
class NumberThread implements Runnable
{
public void run() {
for(int i=1;i<=100;i++) {
System.out.print(i+" ");
}
}
}
编写小程序实现 Runnable 接口,通过多线程实现在小程序窗口中不断的显示 自然数:从 1 到 100。
public class NumberThreadTest {
public static void main(String[] args) {
NumberThread nt=new NumberThread();
Thread t=new Thread(nt);
t.start();
}
}
class NumberThread implements Runnable
{
public void run() {
for(int i=1;i<=100;i++) {
System.out.print(i+" ");
}
}
}