当我尝试使用'split'和trim()读取输入时,抛出-NumberFormatException

用户名
public class Solution {
    public static void main(String[] args) throws IOException,NumberFormatException
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int[] first_line = new int[2];
        String line = br.readLine();
        String[] strs = line.trim().split("\\s+");

        for(int i=0;i<2;i++)
        { 
            first_line[i] = Integer.parseInt(strs[i]);
        }

        int num = first_line[0];
        int tc = first_line[1];
        int[] lane = new int[num];
        String sec_line = br.readLine();
        String[] strs_line = sec_line.trim().split("\\s+");

        for(int i=0;i<num;i++)
        {
            lane[i] = Integer.parseInt(strs_line[i]);
        }

        for(int i=0;i<tc;i++)
        {
            String io = br.readLine();
            String[] ee = io.trim().split("//s+"); 
            int entry = Integer.parseInt(ee[0]);;// This is where my program throws exception
            int exit = Integer.parseInt(ee[1]);
            findMin(lane,entry,exit);
        }
    }

    public static void findMin(int[] lane,int entry,int exit)
    {
        int min = entry;
        for(int i=entry+1;i<exit;i++)
        {
            if(lane[i] < min)
            {
                min = lane[i];
            }
        }
        System.out.println(min);
    }
}
  1. 输入的第一行包含两个整数8 5,其中8是行数,即0-7和5是测试用例数。
  2. 输入的下一行是从0到7的8条通道的宽度,即2 3 1 2 3 2 3 3
  3. 下一行输入是

0 3

4 6

6 7

3 5

0 7

每对之间用空格隔开是车道中的各个入口点和出口点,但是当我尝试阅读时,会抛出一个 NumberFormatException

ho草

从更改您的正则表达式

String[] ee = io.trim().split("//s+");

String[] ee = io.trim().split("\\s+");

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

线程“main”中的异常 java.lang.NumberFormatException:对于输入字符串:“1”。“1”的数字格式例外。虽然使用 trim() 和 split()

当我尝试将整数的文本文件读取为int []时,出现NumberFormatException

尝试使用parseInt()和trim()时,NumberFormatException无法修复它

NumberFormatException:对于输入字符串:尝试使用 apache poi 读取 excel 文件时的“null”

读取文件输入时出现java.lang.NumberFormatException

String to Int 抛出 NumberFormatException

当我使用secureTextEntry = {true}时,输入会在尝试再次键入时重置值

我的代码中的NumberFormatException

当我尝试输入时程序停止工作

在JTextField中使用NumberFormatException

当我尝试使用 Spring 和 file.properties 时,我看到错误

我尝试读取输入时尝试使用“连接”导致R冻结或崩溃

读取此文件输入时,为什么我的程序会因null异常而抛出?

为什么我收到NumberFormatException

为什么我得到NumberFormatException

输入字符串的NumberFormatException

当我尝试使用 java sdk 创建 Stripe Customer 时,它抛出“无效对象”

当我尝试使用 Firebase 注销用户时,为什么 Redux 会抛出空错误?

Groovy和SoapUI-NumberFormatException

当我尝试使用BufferedReader将整数输入存储到数组时遇到数字格式异常

java.lang.NumberFormatException:对于输入字符串:使用Spark从雪花中读取时为“ inf”

java.lang.NumberFormatException:对于输入字符串“”-使用扫描仪读取txt文件时

当我尝试上传到雪花中时,使用put命令和table stage得到错误

当我尝试使用maven和pom.xml更改输出目录时出现错误

当我尝试同时使用CAST和CASE WHEN时,其说法错误

当我尝试使用 python 运行 Glue 作业来关联数组和结构数据时

addEventListener 不是函数错误,当我使用 .split 时

“1”的数字格式例外。虽然使用 trim() 和 split()

java.lang.NumberFormatException:用于输入字符串{Date}。Spring MVC我无法识别错误