for(int i = 0; i < 10; i++){
   System.out.println("Hello, world");
   Thread.sleep(1000);
}
每隔一秒钟打印一行“hello, world”

解决方案 »

  1.   

    for(int i = 0; i < 10; i++){
       System.out.println("Hello, world");
       Thread.sleep(1000);
    }
    每隔一秒钟打印一行“hello, world”
      

  2.   

    for(int i = 0; i < 10; i++){
       System.out.println("Hello, world");
       Thread.sleep(1000);
    }
    每隔一秒钟打印一行“hello, world”
      

  3.   

    可以用Timer的,但是要用事件监听器
    ActionListner al = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.out.println("Hello, world");
        }
    };
    Tiner timer = new Timer(1000, al);
    timer.start();
      

  4.   

    for(int i = 0; i < 10; i++){
       System.out.println("Hello, world");
       Thread.sleep(1000);
    }
      

  5.   

    我想也可以基于汇编变成的方法将空函数进行一定次数的循环以达到的延迟的效果
    不过这种要对使用的空白指令有个很深入的了解我认为还是使用timer比较简单,用多线程也可以接受啦!
      

  6.   

    thread简单,timer麻烦一点,但timer就是为这个所做的,
      

  7.   

    随便写了点^_^public class NewHelloWorld{private Timer timer=null;public NewHelloWorld(){
    timer=new Timer();
    timer.schedule(new SayHello(),0,1000);
    }class SayHello extends Timer{
    public run{
    System.out.println("Hello world");
    }
    }public static void main(String[] args){
    NewHelloWorld nw=new NewHelloWorld();
    }
    }
      

  8.   

    thread的话经常会出现点你想不到的结果
      

  9.   

    for(int i = 0; i < 10; i++){
       System.out.println("Hello, world");   try
    {
      Thread.sleep(10000)   //单位毫秒
    }catch(Exception e)
    {
    System.out.println("ERROR--"+e.getMessage);
    }
    }
    每隔一秒钟打印一行“hello, world”
      
      

  10.   

    循环中加入 Thread.sleep(1000);
      

  11.   

    To:qybao(阿宝)
    Timer timer = new Timer(1000, al);//Timer并没有这个构造函数哈
    timer.start();