Question about InputMismatchException while using Scanner

后端 未结 5 1924
一整个雨季
一整个雨季 2021-01-23 08:50

The question :

Input file: customer’s account number, account balance at beginning of month, transaction type (withdrawal, deposit, in

5条回答
  •  醉酒成梦
    2021-01-23 09:47

    I guess it is a little too late to answer this question, but I recently stumbled upon the same problem, and my googling led me here.

    I think the most common case for InputMismatchException thrown by Scanner.nextDouble() is that your default locale used by your Scanner expects doubles in different format (for example, 10,5, not 10.5). If that is the case, you should use Scanner.useLocale method like this

    Scanner s = new Scanner(System.in);
    s.useLocale(Locale.US);
    

提交回复
热议问题