本文介绍了我们如何在java编程中添加时间延迟?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个程序:
import javax.swing.*;
public static void main()
{
try {
String stringyInp = JOptionPane.showInputDialog( null , "Enter your number" ) ;
int input = Integer.parseInt(stringyInp) ;
}catch(Exception e) {
JOptionPane.showMessageDialog(null ,"Enter only numerical values") ; //i want here to add a time delay of 3 seconds!How?
main();
}
System.out.print( FACTORIAL(input)) ;
}// instance variables - replace the example below with your own
public static int FACTORIAL(int number )
{
if (number == 0){
return 1 ;
}
else {
return FACTORIAL(number-1) * number ;
}
那么我们如何添加时间延迟,我们如何执行延迟 3 秒的指令??我想在这个程序中添加 3 秒或 2 秒的延迟...
So how can we add time delay ,how can we execute an instruction with a delay of 3 seconds?? I would like in this program to add a delay of 3 seconds or 2 seconds...
推荐答案
我认为您可以使用此代码.
I think you can use this code.
try {
Thread.sleep(1000);
} catch(InterruptedException ex) {
Thread.currentThread().interrupt();
}
这篇关于我们如何在java编程中添加时间延迟?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!