Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/17.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 当我尝试使用';拆分';and trim()抛出-NumberFormatException 公共类解决方案{ 公共静态void main(字符串[]args)引发IOException、NumberFormatException { BufferedReader br=新的BufferedReader(新的InputStreamReader(System.in)); int[]第一行=新int[2]; String line=br.readLine(); 字符串[]strs=line.trim().split(\\s+); 对于(inti=0;i_Java_Split_Trim_Numberformatexception_Parseint - Fatal编程技术网

Java 当我尝试使用';拆分';and trim()抛出-NumberFormatException 公共类解决方案{ 公共静态void main(字符串[]args)引发IOException、NumberFormatException { BufferedReader br=新的BufferedReader(新的InputStreamReader(System.in)); int[]第一行=新int[2]; String line=br.readLine(); 字符串[]strs=line.trim().split(\\s+); 对于(inti=0;i

Java 当我尝试使用';拆分';and trim()抛出-NumberFormatException 公共类解决方案{ 公共静态void main(字符串[]args)引发IOException、NumberFormatException { BufferedReader br=新的BufferedReader(新的InputStreamReader(System.in)); int[]第一行=新int[2]; String line=br.readLine(); 字符串[]strs=line.trim().split(\\s+); 对于(inti=0;i,java,split,trim,numberformatexception,parseint,Java,Split,Trim,Numberformatexception,Parseint,将正则表达式从 String[]ee=io.trim().split(//s+”); 到 String[]ee=io.trim().split(\\s+);对于给定的输入,ee[0]包含“03”,ee[1]为空。“03”是异常的原因,因为它无法解析为int 使用空格分隔数字,而不是“//s+” 你确定数组中的条目不是空字符串吗?在将其解析为int之前,你是否尝试过打印字符串?这将帮助你解决问题。//s+和\\s+不是一回事。@Mureinik我正在运行一个自动测试用例,我确信它不是空的strin

将正则表达式从

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


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

对于给定的输入,ee[0]包含“03”,ee[1]为空。“03”是异常的原因,因为它无法解析为int

使用空格分隔数字,而不是“//s+”


你确定数组中的条目不是空字符串吗?在将其解析为
int
之前,你是否尝试过打印字符串?这将帮助你解决问题。
//s+
\\s+
不是一回事。@Mureinik我正在运行一个自动测试用例,我确信它不是空的string@NPE现在我明白了谢谢!!我太傻了!这是一个打字错误!如果做得正确,
\\s+
与空白是一样的-它只覆盖了不止一个空格。
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);
    }
}
String[] ee = io.trim().split(" ");