Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.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 如何使用split方法查找.txt的两个特定双精度列的平均值_Java_Arrays_Split - Fatal编程技术网

Java 如何使用split方法查找.txt的两个特定双精度列的平均值

Java 如何使用split方法查找.txt的两个特定双精度列的平均值,java,arrays,split,Java,Arrays,Split,我需要读取这个.txt文件的行/将它们存储到一个数组中,同时忽略T,只使用本文中MaxT和MinT列中的数字,找到MaxT和MinT的平均值,然后将它们打印到GUI的标签上。在阅读了这些行并用它们之间的标签将它们分开之后,我现在被卡住了 Day MaxT MinT AvgT Dept HDD CDD Prep NewSnow 1 61 38 49.5 17.8 15 0 0.00 0.0 2 60 33 46.5 14.

我需要读取这个.txt文件的行/将它们存储到一个数组中,同时忽略T,只使用本文中
MaxT
MinT
列中的数字,找到
MaxT
MinT
的平均值,然后将它们打印到GUI的标签上。在阅读了这些行并用它们之间的标签将它们分开之后,我现在被卡住了

Day MaxT    MinT    AvgT    Dept    HDD CDD Prep    NewSnow
1   61  38  49.5    17.8    15  0   0.00    0.0
2   60  33  46.5    14.7    18  0   0.93    0.0
3   60  36  48.0    16.0    17  0   0.80    0.0
4   36  22  29.0    -3.1    36  0   T   T
5   43  18  30.5    -1.8    34  0   0.00    0.0
6   47  22  34.5    2.1 30  0   0.00    0.0
7   53  31  42.0    9.4 23  0   0.00    0.0
8   45  23  34.0    1.2 31  0   0.27    2.1
9   24  15  19.5    -13.5   45  0   0.14    2.0
10  18  11  14.5    -18.7   50  0   0.03    0.7
11  25  11  18.0    -15.4   47  0   T   T
12  28  18  23.0    -10.6   42  0   0.01    0.2
13  19  10  14.5    -19.3   50  0   T   T
14  21  11  16.0    -18.1   49  0   0.17    2.9
15  36  21  28.5    -5.8    36  0   T   0.0
16  38  25  31.5    -3.1    33  0   0.02    0.0
17  36  26  31.0    -3.8    34  0   T   T
18  44  27  35.5    0.4 29  0   0.00    0.0
19  66  39  52.5    17.1    12  0   0.00    0.0
20  72  49  60.5    24.9    4   0   0.00    0.0
21  59  41  50.0    14.1    15  0   1.57    0.0
22  50  33  41.5    5.3 23  0   0.00    0.0
23  56  32  44.0    7.5 21  0   0.02    0.0
24  61  33  47.0    10.2    18  0   1.03    T
25  37  32  34.5    -2.6    30  0   0.04    0.5
26  38  31  34.5    -2.9    30  0   T   T
27  52  27  39.5    1.7 25  0   0.00    0.0
28  66  42  54.0    15.9    11  0   T   0.0
29  60  38  49.0    10.8    16  0   0.21    0.0




try{
     File inputFile = new File("climateDataCincinnati.txt"); //get text 
                    Scanner in = new Scanner(inputFile); //scanner for text
                    String line = "";
                    in.nextLine(); //to consume the first row
                    while(in.hasNextLine()){ //while there is a next line do
                        line = in.nextLine(); //take line
                        String content[] = line.split("\t"); // split by tabs
//where to seperate the two columns from the others 
                }
                catch (IOException exception){
                    System.out.println(exception.toString());
                }

只需在列表中存储所需的列。您还可以在遍历值时将字符串解析为整数

List<Integer> maxList = new ArrayList<Integer>();
List<Integer> minList = new ArrayList<Integer>();

while(in.hasNextLine()){ //while there is a next line do
   line = in.nextLine(); //take line
   String content[] = line.split("\t"); // split by tabs
   //get the maxT and minT
   Integer maxT = Integer.valueOf(content[1]);
   Integer minT = Integer.valueOf(content[2]);
   //store for future use
   maxList.add(maxT); 
   minList.add(minT);
   }

//Do something on your 2 lists to find the average
List maxList=new ArrayList();
List minList=new ArrayList();
while(in.hasNextLine()){//while有下一行do
line=in.nextLine();//使用line
字符串内容[]=line.split(“\t”);//按制表符拆分
//得到最大和薄荷糖
Integer maxT=Integer.valueOf(content[1]);
整数minT=Integer.valueOf(content[2]);
//储存以备将来使用
maxList.add(maxT);
添加(薄荷);
}
//在你的两张清单上做点什么,找出平均值

只需将所需的列存储在列表中即可。您还可以在遍历值时将字符串解析为整数

List<Integer> maxList = new ArrayList<Integer>();
List<Integer> minList = new ArrayList<Integer>();

while(in.hasNextLine()){ //while there is a next line do
   line = in.nextLine(); //take line
   String content[] = line.split("\t"); // split by tabs
   //get the maxT and minT
   Integer maxT = Integer.valueOf(content[1]);
   Integer minT = Integer.valueOf(content[2]);
   //store for future use
   maxList.add(maxT); 
   minList.add(minT);
   }

//Do something on your 2 lists to find the average
List maxList=new ArrayList();
List minList=new ArrayList();
while(in.hasNextLine()){//while有下一行do
line=in.nextLine();//使用line
字符串内容[]=line.split(“\t”);//按制表符拆分
//得到最大和薄荷糖
Integer maxT=Integer.valueOf(content[1]);
整数minT=Integer.valueOf(content[2]);
//储存以备将来使用
maxList.add(maxT);
添加(薄荷);
}
//在你的两张清单上做点什么,找出平均值

MaxT是索引1,而
MinT
是分割每行时的索引2。一旦你把这些数据解析出来,就很容易从一个数字列表中得到一个平均值。那么,你到底被卡住了多少?空格呢?
MaxT
是索引1,
MinT
是拆分每一行时的索引2。一旦你把这些数据解析出来,就很容易从一个数字列表中得到一个平均值。那么,你到底是如何被困的呢?