2017-04-21 65 views
-3
import java.util.Scanner; 

public class Solution { 

    public static void main(String[] args) { 
     Scanner scan = new Scanner(System.in); 
     int i = scan.nextInt(); 
     String s = scan.nextLine(); 
     double d = scan.nextDouble(); 
     System.out.println("String: " + s); 
     System.out.println("Double: " + d); 
     System.out.println("Int: " + i); 
    } 
} 
+0

之後加上另一個String s = scan.nextLine();以清除您的輸入。 – BlackHatSamurai

+1

尋求調試幫助的問題(「爲什麼這個代碼不工作?」)必須包含所需的行爲,特定的問題或錯誤以及在問題本身中重現問題所需的最短代碼。沒有明確問題陳述的問題對其他讀者無益。請參閱:如何創建[mcve] – GhostCat

+0

但在我的情況下,當我單擊運行時沒有任何反應 –

回答

1

你的代碼運行,但你應該添加一些用戶提示:

import java.util.Scanner; 

public class TimeTest { 

    public static void main(String[] args) { 
     Scanner scan = new Scanner(System.in); 
     System.out.println("Input integer:"); 
     int i = scan.nextInt(); 
     System.out.println("Input string:"); 
     String s = scan.nextLine(); 
     System.out.println("Input double:"); 
     double d = scan.nextDouble(); 
     System.out.println("String: " + s); 
     System.out.println("Double: " + d); 
     System.out.println("Int: " + i); 
    } 
} 

應當注意的是,你將有一個問題,試圖讓你的字符串輸入。您需要在String s = scan.nextInt();