keyboard.next没有接收输入

时间:2016-05-05 14:08:16

标签: java java.util.scanner

由于某些原因,我的键盘在提示时不会输入任何内容。这是我的代码:

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();
    }
}

1 个答案:

答案 0 :(得分: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);