如何使它在对话之间有一段等待时间

时间:2013-07-17 03:55:56

标签: java

我将如何制作它以便在System.out.println之间暂停,所以它不会立即全部溢出,

import java.io.*;
import java.util.Scanner;
public class tester {
public static void main(String[] args) {
    System.out.println("Stranger: Good morning");
    System.out.println("Stranger: you had a terrible Dream..");
    System.out.println("Stranger: what is your name?");
    System.out.print("Name:");
    Scanner kbReader = new Scanner (System.in); 
    String s = kbReader.next();
    System.out.println("Nice to meet you " + s);
    System.out.println("my name is Master Wizard.");
    System.out.println("");
    System.out.println("");
    System.out.println("");
    System.out.println("");
    System.out.println("");
    }
 }

1 个答案:

答案 0 :(得分:3)

您可以尝试类似......

import java.util.Scanner;

public class Test {

    public static void main(String[] args) {
        System.out.println("Stranger: Good morning");
        delay(500);
        System.out.println("Stranger: you had a terrible Dream..");
        delay(500);
        System.out.println("Stranger: what is your name?");
        System.out.print("Name:");
        Scanner kbReader = new Scanner(System.in);
        String s = kbReader.next();
        System.out.println("Nice to meet you " + s);
        System.out.println("my name is Master Wizard.");
        System.out.println("");
        System.out.println("");
        System.out.println("");
        System.out.println("");
        System.out.println("");
    }

    public static void delay(int millis) {
        try {
            Thread.sleep(millis);
        } catch (InterruptedException exp) {
        }
    }
}

例如