Java数字格式异常
我在Java数字格式异常,java,java.util.scanner,bufferedreader,numberformatexception,Java,Java.util.scanner,Bufferedreader,Numberformatexception,我在CodeChef平台上解决问题时遇到了NumberFormatException 首先,我使用Scanner处理输入,然后使用BufferedReader。但是没有一个成功 这是我的密码: 文件: * Thrown to indicate that the application has attempted to convert * a string to one of the numeric types, but that the string does not * have the ap
CodeChef
平台上解决问题时遇到了NumberFormatException
首先,我使用Scanner
处理输入,然后使用BufferedReader
。但是没有一个成功
这是我的密码:
文件:
* Thrown to indicate that the application has attempted to convert
* a string to one of the numeric types, but that the string does not
* have the appropriate format.
异常将在int t=Integer.parseInt(br.readLine())行抛出代码>。在那里引发异常的原因是您在那里读取的输入没有数字。如果是数字+字符串或其他内容,则会抛出NumberFormatException
示例输入1235a
这将引发异常,并显示以下消息:
java.lang.NumberFormatException:用于输入字符串:“1235a”
因此,您应该调试那里的输入。文档:
* Thrown to indicate that the application has attempted to convert
* a string to one of the numeric types, but that the string does not
* have the appropriate format.
异常将在int t=Integer.parseInt(br.readLine())行抛出代码>。在那里引发异常的原因是您在那里读取的输入没有数字。如果是数字+字符串或其他内容,则会抛出NumberFormatException
示例输入1235a
这将引发异常,并显示以下消息:
java.lang.NumberFormatException:用于输入字符串:“1235a”
所以你应该调试那里的输入。你给它什么输入?int t=Integer.parseInt(br.readLine())代码>确保br.readLine()
的值为纯数值,它是一个从1到50的整数,并且正在通过所有自定义测试用例。使用调试器,在引发异常的行之前停止,并查看br.readLine()
值,然后你可能会看到这不仅仅是一个数字。你给它什么输入?int t=Integer.parseInt(br.readLine())代码>确保br.readLine()
的值为纯数值,它是一个从1到50的整数,并且正在通过所有自定义测试用例。使用调试器,在引发异常的行之前停止,并查看br.readLine()
值,输入:输入的第一行包含一个表示测试用例数量的整数T。T测试用例的描述如下。每个测试用例的第一行(也是唯一一行)包含一个表示引号的字符串S。从异常中,您会得到一条消息,即您的输入为null
,这意味着没有给出任何输入。输入:输入的第一行包含一个整数T,表示测试用例的数量。T测试用例的描述如下。每个测试用例的第一行(也是唯一一行)包含一个表示引号的字符串S。从异常中,您会得到一条消息,即您的输入为null
,这意味着没有给出任何输入。这会导致您的异常。
* Thrown to indicate that the application has attempted to convert
* a string to one of the numeric types, but that the string does not
* have the appropriate format.