Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/306.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java数字格式异常_Java_Java.util.scanner_Bufferedreader_Numberformatexception - Fatal编程技术网

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.