2016-05-05 89 views
-2

出於某種原因,我的鍵盤在提示時不會輸入任何內容。這裏是我的代碼:keyboard.next無法接收輸入

import java.util.Scanner; 

public class ForgetfulMachine { 
    public static void main(String[] args) { 
     Scanner keyboard = new Scanner(System.in); 

     System.out.println("What city is the capital of France?"); 
     keyboard.next(); 

     System.out.println("What is 6 multiplied by 7?"); 
     keyboard.nextInt(); 

     System.out.println("Enter a number between 0.0 and 1.0"); 
     keyboard.nextDouble(); 

     System.out.println("Is there anything else you would like to say?"); 
     keyboard.next(); 
    } 
} 
+0

那你試着寫控制檯? – Tom

+1

您沒有使用'keyboard.next()'返回的值' –

+1

您是否試圖獲取您正在輸入的值?因爲你的代碼接受任何東西,只是在 –

回答

0

您需要存儲由next()返回到一些變量的值,例如:

String input = keyboard.next(); 
// for int or float input, use appropriate variable type to store the input 

// possibly print it to the console 
System.out.println("You entered: " + input);