I have one CSV file containing so many attribute but i want max and min values of particular specified columns.
I have write following code for finding minimum value from each specified column,but i got only minimum of last column, not all column.
In dataset.csv file contains
25,185,98,65
15,-20,6,95
17,20005,63,-78
12,-189,-185,54
13,12500,36,-10
If give identifier=3 and location are 0,1,3....so answer will be 12,-189,-78 for minimum.
So please help me to find solution for it.
public static void main(String args[])throws IOException
{
int q,i,loc[];
DataInputStream din = new DataInputStream(System.in);
System.out.println("Enter No. of Idenifier =");
q=Integer.parseInt(din.readLine());
loc= new int[q];
for(i=0;i<q;i++)
{
System.out.println("Enter "+i+"th identifier location :");
loc[i]=Integer.parseInt(din.readLine());
}
BufferedReader CSVFile = new BufferedReader(new FileReader("dataset.csv"));
String dataRow = CSVFile.readLine(); // Read first line.
int min[]=new int[q],max[]=new int[q];
int dataIndex = 0;
while (dataRow != null)
{
String[] dataArray = dataRow.split(",");
for (String item:dataArray) {
if(item.length()==0)
System.out.print("no records found..." + "\t");
else{ continue;}
}
String aspStr = null;
for(int j=0;j<q;j++)
{
aspStr += dataArray[loc[j]]+",";//+dataArray[loc[1]]+","+dataArray[loc[2]];
if((min[j])<Integer.parseInt(dataArray[loc[j]]))
{
min[j]=min[j];
}
else
{
min[j]=Integer.parseInt(dataArray[loc[j]]);
}
}
dataRow = CSVFile.readLine();// Read next line of data.
}
System.out.println("min0 min1 min2="+min[0]+" "+min[1]+" "+min[2]);
}
So above code give only correct output for min[2] only.
thank you.