Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/394.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.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_String_Syntax_Io_Split - Fatal编程技术网

正在分析字符串[]Java中的整数对

正在分析字符串[]Java中的整数对,java,string,syntax,io,split,Java,String,Syntax,Io,Split,我将如何解析字符串数组中第一个字符串之后的整数对。在下面的while循环中,我分配了字母‘A’、‘B’、‘C’,但现在我尝试将成对的数字分配给类输入,例如,类X(inti,intj),有人知道从这里做什么吗 An example input would be : A 32 12 34 12 B 12 22 11 11 C 1 4 1 2 public static void readFile(String f) throws IOException { B

我将如何解析字符串数组中第一个字符串之后的整数对。在下面的while循环中,我分配了字母‘A’、‘B’、‘C’,但现在我尝试将成对的数字分配给类输入,例如,类X(inti,intj),有人知道从这里做什么吗

An example input would be : 
A 32 12 34 12 
B 12 22 11 11
C 1  4   1  2

 public static void readFile(String f) throws IOException {
            BufferedReader in = new BufferedReader(new FileReader(f));
            String line;
            String[] str;
            Scanner s;
            try {

                line = in.readLine();
                s = new Scanner(line);
                int number = s.nextInt();
                if (s.hasNextInt()) {
                    number = s.nextInt(); 
                } 
                s.close();
                line = in.readLine(); 
                numLines = Integer.parseInt(line);

                while((line = input.readLine())!=null){
                      String[] pair = line.split(" ");
                      String letter;        
                      letter = pair[0];
                  }

                if (!numLines.equals(lineCount)) { 
                System.exit(0);
                }           
            } catch (Exception e) {
            } finally {
                in.close(); 
            }
        }

您需要拆分行,然后解析各个数字

大概是这样的:

String[] a = {"A 32 12 34 12","B 12 22 11 11", "C 1  4   1  2"};
    
for (String s: a) {
    String[] line = s.split("\\s+");
    
    for (int i = 1; i < line.length; i++) {
        System.out.print(Integer.parseInt(line[i]) + " ");
    }
    System.out.println();
}
String[]a={“a 32 12 34 12”,“B 12 22 11”,“C 1 4 1 2”};
for(字符串s:a){
字符串[]行=s.split(\\s+);
对于(int i=1;i
输出:

3223412

12 22 11 11

1 4 1 2

为了举例,我使用数组来展示它是如何工作的。您可以根据自己的需求进行更改。您在问题中注意到关于
类x(…)
的一些内容,但是您的代码中没有任何内容显示这一点,因此我不想费心显示一些我不理解的内容


您说您想对整数做些什么,但我在代码中看到的只是字符串。这无法编译。您正在关闭从未定义的
input