如何延迟我的程序,以便在文本之间暂停?

时间:2015-07-31 04:47:51

标签: java text delay

我的代码示例:

System.out.println("Why hello there!");
System.out.println("Welcome to 'Ancient Battles and Adventures!");
***DELAY WOULD GO HERE***
System.out.println("Now, what is your name?");

2 个答案:

答案 0 :(得分:3)

public class MyClass {
    public static void main(String[] args) {
        System.out.println("Why hello there!");
        System.out.println("Welcome to 'Ancient Battles and Adventures!");
        try {
            Thread.sleep(x);
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println("Now, what is your name?");
    }
}

答案 1 :(得分:0)

您可以尝试此代码以获得成功

class ex 
{ 
    public static void main(String args[])
    {
        System.out.println("Why hello there!");
        System.out.println("Welcome to 'Ancient Battles and Adventures!");
        try
        {
            Thread.sleep(1000);// here you can delay for one second
        }
        catch(Exception e) {
            e.printStackTrace();
        }

        System.out.println("Now, what is your name?");
    }
}