课程作业中的输入不匹配期望错误

时间:2017-11-10 12:54:02

标签: java eclipse

所以我明天就得到了我的第一件coursework而且我一直在error,我无法修复它,我不是在找人给我解决方案但是我们非常感谢一些指导。

我正在使用的代码是:

double discountRate = 20;
int totalBookings = 0;

while (S.hasNext()) {
    // String seatType = S.next();
    double price = S.nextDouble();
    int bookings = S.nextInt();

    System.out.format("Seat Type  : %s, ", S.next());

    //sums 

    System.out.format("Seat Price : £%.2f, Bookings : %d", price, bookings);

    //totalBookings = totalBookings + bookings;
    totalBookings += bookings;

    System.out.format("Total Bookings : %d", totalBookings);

谢谢!

enter image description here

1 个答案:

答案 0 :(得分:0)

仔细查看错误消息。堆栈跟踪显示调用Scanner.nextDouble()时发生错误。现在看一下该方法的documentation。它说:

  

将输入的下一个标记扫描为double。这个方法会抛出   InputMismatchException如果下一个标记无法转换为   有效的双重值。

看看你的输入。第一个标记是“1ST(表格)”。包含字母的令牌对nextDouble()无效。