怎样在两行代码间延时? for(int i = 0; i < 10; i++){ System.out.println("Hello, world"); Thread.sleep(1000);}每隔一秒钟打印一行“hello, world” 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 for(int i = 0; i < 10; i++){ System.out.println("Hello, world"); Thread.sleep(1000);}每隔一秒钟打印一行“hello, world” for(int i = 0; i < 10; i++){ System.out.println("Hello, world"); Thread.sleep(1000);}每隔一秒钟打印一行“hello, world” 可以用Timer的,但是要用事件监听器ActionListner al = new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("Hello, world"); }};Tiner timer = new Timer(1000, al);timer.start(); for(int i = 0; i < 10; i++){ System.out.println("Hello, world"); Thread.sleep(1000);} 我想也可以基于汇编变成的方法将空函数进行一定次数的循环以达到的延迟的效果不过这种要对使用的空白指令有个很深入的了解我认为还是使用timer比较简单,用多线程也可以接受啦! thread简单,timer麻烦一点,但timer就是为这个所做的, 随便写了点^_^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();}} thread的话经常会出现点你想不到的结果 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” 循环中加入 Thread.sleep(1000); To:qybao(阿宝)Timer timer = new Timer(1000, al);//Timer并没有这个构造函数哈timer.start(); new一个对象数组时,如果没有默认构造器,是不是就不调用构造器了? JAVA 构造对象的问题 讨论下:JAVA实现打印的最优方法是什么? 本地部署不出错,发布出错,求原因 关于多线程,请高手指教! 讨论个基础问题,关于APPLET 请助 为什么下列语句有错误? 一个很蠢的问题 这个程序哪里错了,怎么提示18个错?倒…… 将字符串写入一个文件的问题 解析XML错误:Invalid encoding name "GBK".???
System.out.println("Hello, world");
Thread.sleep(1000);
}
每隔一秒钟打印一行“hello, world”
System.out.println("Hello, world");
Thread.sleep(1000);
}
每隔一秒钟打印一行“hello, world”
ActionListner al = new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("Hello, world");
}
};
Tiner timer = new Timer(1000, al);
timer.start();
System.out.println("Hello, world");
Thread.sleep(1000);
}
不过这种要对使用的空白指令有个很深入的了解我认为还是使用timer比较简单,用多线程也可以接受啦!
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();
}
}
System.out.println("Hello, world"); try
{
Thread.sleep(10000) //单位毫秒
}catch(Exception e)
{
System.out.println("ERROR--"+e.getMessage);
}
}
每隔一秒钟打印一行“hello, world”
Timer timer = new Timer(1000, al);//Timer并没有这个构造函数哈
timer.start();