2013-07-17 34 views
0

之間的等待時間如何將我讓這個在之間的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

我本來以爲掃描儀將停止,直到你輸入一些東西,然後按回車鍵 – MadProgrammer

+0

這樣做,但我想它,以便System.out.println(「陌生人:早上好」); System.out.println(「陌生人:你有一個可怕的夢..」); System.out.println(「陌生人:你叫什麼名字?」); sores有一點時間讓他們讀它 –

+0

你想要什麼類型的停頓?延遲(如1秒),或者你想讓用戶不得不按下一個鍵 – MadProgrammer

回答

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) { 
     } 
    } 
} 

例如

+0

是否編譯過? –

+0

達成文件結束 –

+1

這是一個代碼片段。你需要包裝一個類... – MadProgrammer

相關問題