我已经搜索过,但我似乎真的找不到代码中的任何错误,请帮助!
代码可以编译,但这是我想回答问题 3 时遇到的错误:
Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Unknown Source)
at java.util.Scanner.next(Unknown Source)
at java.util.Scanner.nextDouble(Unknown Source)
at ForgetfulMachine.main(ForgetfulMachine.java:16)
这是我的代码:
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 Germany?" );
keyboard.next();
System.out.println( "What is 6 divided by 2?" );
keyboard.nextInt();
System.out.println( "What is your favorite number between 0.0 and 1.0?" );
keyboard.nextDouble();
System.out.println( "Is there anything else you would like to tell me?" );
keyboard.next();
}
}