【发布时间】:2017-06-15 04:03:00
【问题描述】:
public static int processData(ArrayList<String> array)
{
ArrayList <Integer> no=new ArrayList<Integer>();
Iterator it=array.iterator();
String[] strValues;
while(it.hasNext())
{
strValues = array.toString().split(",");
System.out.println(it.next());
strValues = array.toString().split(",");
no.add(0,strValues[2]);
no.add(1,strValues[6]);
strValues = array.toString().split(",");
}
return 1;
}
public static void main (String[] args) {
ArrayList<String> inputData = new ArrayList<String>();
try {
Scanner in = new Scanner(new BufferedReader(new FileReader("D:\\dmo\\input.txt")));
while(in.hasNextLine()) {
String line = in.nextLine().trim();
if (!line.isEmpty()) // Ignore blank lines
inputData.add(line);
}
int retVal = processData(inputData);
PrintWriter output = new PrintWriter(new BufferedWriter(new FileWriter("D:\\dmo\\output.txt")));
output.println("" + retVal);
output.close();
} catch (IOException e) {
System.out.println("IO error in input.txt or output.txt");
}
}
}
输入文本文件包含记录为 20, AB CD ,55 ,876000 22,约翰卡特,57,987520 23,亚伯拉罕,55,5420130 24,玛丽亚,55,8952403 25,瑟琳娜,57,7895421
此数据作为 Arraylist 数组传递给 processData() 函数。我想计算同一部门ID的平均工资。例如。平均 55 次
【问题讨论】:
-
是
987520 23代码还是数字?它之间有一个空格。 -
输入文本包含 20, AB CD ,55 ,876000 22, John Carter, 57,987520 23, abrahim ,55,5420130 24,mariya , 55,8952403 25,serena , 57,7895421 first no是e-id,2是姓名,3rd是depart-id,4是salary
-
@LKTN.25 它的号码,它是 22,John Carter,57,987520,
标签: java string arraylist collections