成功解决Java 报错: Exception in thread "main" java.util.InputMismatchException

时间:2024-03-27 10:22:12

问题描述

今天在写金额中文大写转换的时候,运行程序发现输入整数就没问题,输入小数报错:
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.nextInt(Unknown Source)
at java.util.Scanner.nextInt(Unknown Source)
at ex1.Ex1.main(Ex1.java:9)

成功解决Java 报错: Exception in thread "main" java.util.InputMismatchException

解决方法:

参考了博客
https://www.cnblogs.com/chenyanlong/p/7667438.html

发现输入的是浮点数,高亮处应该用nextDouble()。
成功解决Java 报错: Exception in thread "main" java.util.InputMismatchException

修改后:成功!成功解决Java 报错: Exception in thread "main" java.util.InputMismatchException