这是什么错误?我收到了inputmismatchexception

时间:2019-10-01 12:17:02

标签: java exception runtime-error inputmismatchexception

我正在编写一个小程序,但它会引发inputmismatchexception。 enter image description here这是怎么了?`错误信息如下。

What is the three letter currency symbol for your travel destination? How many  are there in 1 USD? MCX
Exception in thread "main" java.util.InputMismatchException
at java.base/java.util.Scanner.throwFor(Unknown Source)
at java.base/java.util.Scanner.next(Unknown Source)
at java.base/java.util.Scanner.nextFloat(Unknown Source)
at TripPlanner.main(TripPlanner.java:30)
    {
        System.out.println("Welcome to Vacation PLanner!");
        System.out.print("What is your name? ");

        Scanner input = new Scanner(System.in);
        String name = input.nextLine();

        System.out.print("Nice to meet you " + name + ", where are you travelling to? ");
        String city = input.nextLine();

        System.out.println("Great! " + city + " sounds like a great trip");
        System.out.println("***********");

        System.out.print("How many days are you going to spend travelling? ");
        int days = input.nextInt();

        System.out.print("How much money, in USD, are you planning to spend on your trip? ");
        int money = input.nextInt();

        System.out.print("What is the three letter currency symbol for your travel destination? ");
        String currencySymbol;
        currencySymbol = input.nextLine();

        System.out.print("How many " + currencySymbol + " are there in 1 USD? ");
        float exchangeRate = input.nextFloat();
    }
}`

0 个答案:

没有答案