I am working with CSVfile program.
I have already calculate something from it.
Name,Age,Sex,Pincode,Disease
1. aaa,4,M,35265,flu
2. bbb,4,M,35652,Gastric
3. eee,6,F,35265,Brain
4. sss,7,M,32564,flu
I have made program for calculating no. of age,sex and pincode as attached in the code.
In this i have calculated that age=4 comes how many times and also how many distinct ages are there ion the file.
Also Original file has so many records , nearly 100 records(Rows).
Now i am stuck with one problem.
I just want to find that there are how many rows having age=4 and sex=M or sex=M and pincode=35265 or age=4 and Pincode=35265
Name and disease is not required in the whole processing.It is left as it is.There is no need to compare name and disease.
Only particular elements of one row is compared with the same elements of the other row.
It always execute else method and gives output "Something Wrong"...
i also attached my code with this.
import java.io.*;
import java.lang.*;
import java.util.Arrays;
public class CSVRead{
int x;
int y;
public static void main(String[] args) throws IOException {
System.out.println("Enter the value of K=");
DataInputStream din = new DataInputStream(System.in);
String n = din.readLine();
int k = Integer.parseInt(n);
System.out.println("\n"+k);
BufferedReader CSVFile =
new BufferedReader(new FileReader("C:/Users/JAL/Desktop/dataset.csv"));
String dataRow = CSVFile.readLine(); // Read first line.
// The while checks to see if the data is null. If
// it is, we've hit the end of the file. If not,
// process the data.
int j=0,i=0,z1=0;
int p=0,z=0,k1=0,age=0;
int pp=0;
int a[][] = new int[100][1];
int s1[] = new int [2];
int p2[][] = new int[120][2];
int as[][] = new int[120][2];
int se[] = new int[120];
for (int s = 0 ; s < p2.length; s++)
{
p2[s][0] = 0;
p2[s][1] = 0;
as[s][0]=0;
as[s][1]=0;
}
for (int s = 0 ; s < 100; s++)
{
a[s][0] = 0;
}
while (dataRow != null)
{
String[] dataArray = dataRow.split(",");
for (String item:dataArray) {
if(item.length()==0)
System.out.print("?" + "\t");
else{}
//System.out.print(dataArray[1] + "\t");
}
//System.out.println(dataArray[1]); // Print the data line.
//-------------------------------------------------------------------------------------------------------------------------------------------
String v = dataArray[1]; //For calculation of particular age
int x = Integer.parseInt(v);
a[x][0] = a[x][0] + 1;
int x4 = x;
//-------------------------------------------------------------------------------------------------------------------------------------------
String v1 = dataArray[2];
if(v1.equals("male"))
{
s1[0] = s1[0] + 1;
//se[pp] = 0;
}
else if(v1.equals("female"))
{
s1[1] = s1[1] + 1;
//se[pp] = 1;
}
else
{ System.out.println("Something wrong");}
//pp++;
//-------------------------------------------------------------------------------------------------------------------------------------------
String v2 = dataArray[3];
int x1 = Integer.parseInt(v2);
z1 = 0;
for(int s=0;s<p2.length;s++)
{
if( p2[s][0]==x1 )
{
p2[s][1] = p2[s][1]+1;
}
else
{
z1++;
}
}
if (z1 == p2.length)
{
p2[z][0] = x1 ;
p2[z][1]=p2[z][1]+1;
}
z++;
//------------------------------------------------------------------------------------------------------------------------------------------
for(int s=0;s<a.length;s++)
{
if(v1.equals("male") && a[s][0]==x)
{
as[s][0] = a[s][0];
as[s][1] = as[s][1]+1;
}
else if(a[s][0]==x4 && v1.equals("female") )
{
as[s][0] = a[s][0];
as[s][1] = as[s][1]+1;
}
else
{
System.out.println("Something wrong");
}
}
//------------------------------------------------------------------------------------------------------------------------------------------
dataRow = CSVFile.readLine();// Read next line of data.
}
// Close the file once all data has been read.
CSVFile.close();
// End the printout with a blank line.
System.out.println();
} //main()
} // CSVRead
So please help me to get desired output.
Thank you..