I have input in a file named match.csv.
the contents are
abc,2,jpg,6,ghi,1,
def,3,del,7,jpg,2,
ghi,4,abc,8,klm,3,
klm,5,klm,9,ijl,4,
I want to print all the repeated values of words along with assoicated number
So the result for above should be
abc,2
abc,8
ghi,4
ghi,1
klm,5
klm,9
klm,3
jpg,6
jpg,2
the input may be large and consist of many more rows.
I coded the following, but values are not getting printed as what I expect.
import java.io.File;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.io.*;
import java.util.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class match {
private static File outputFile;
static public void main(String args[])
{
int x = 0;
int ucount;
double[] num = new double[100];
String[] group = new String[100];
String[] group1 = new String[13];
String[] group2 = new String[13];
double[] values = new double[100];
String[] groupo = new String[100];
int tokenslength = 100;
try {
Scanner input = new Scanner(new File("match.csv"));
Scanner infile2 = new Scanner(new File("number.csv")); //called after creating above
PrintWriter output = new PrintWriter(new File("test2_output.csv"));
PrintWriter groutput = new PrintWriter(new File("group.csv")); //created and filled during runtime
PrintWriter nboutput = new PrintWriter(new File("number.csv"));//created and filled during runtime
//---------------------------------------------------------------//
while(input.hasNext())
{
String line = input.nextLine();
StringTokenizer st = new StringTokenizer(line, ",");
String[] tokens = line.split(",");
for(int i = 0; i < tokens.length; i=i+2)
{ group[i] = tokens[i];
// System.out.println("" + group[i]);
groutput.print("" + group[i]);
groutput.print(",");
}
for(int j = 1; j < tokens.length; j=j+2)
{
values[j] = Double.parseDouble(tokens[j]);
num[j] = values[j];
nboutput.print("" + num[j]);
nboutput.print(",");
}
} //end while
groutput.close();
nboutput.close();
output.close();
} //end try
catch(Exception e) {
}
//-----------------------------------------------------------------//
try {
Scanner infile1 = new Scanner(new File("group.csv")); //called after creating above
while(infile1.hasNext())
{
String line1 = infile1.nextLine();
StringTokenizer st1 = new StringTokenizer(line1, ",");
String[] tokens1 = line1.split(",");
for(int d = 0; d < tokens1.length; d++)
{
group1[d] = tokens1[d];
group2[d] = group1[d];
System.out.print("" + group1[d]);
System.out.print(",");
}
System.out.println("----------");
} //end while
//pseudo code
int pal=0;
int q=0;
int h=0;
System.out.println("" + group1.length);
System.out.println("" + group2.length);
for ( q=0; q<group2.length; q++)
{
for ( h=0; h<group1.length; h++)
{
if(group2[q].equals(group1[h]))
{
pal++;
}
if( pal>2)
{
System.out.println("" + group1[h]);
}
}
}
//pseudo code
/*String maximum = group1[8];
for (int h=1; h<group1.length; h++) {
if (group1[h] == maximum) {
System.out.println("" + group1[h]); // new maximum
System.out.println("" + h);
}
}*/
} //end try
catch(Exception e) {
}
//-----------------------------------------------------------------//
}
}
My concept here is
take input from match.csv and then separate the words and numbers.
Then put the groups in an array and compare each element with every other, such that we can print the repeated values.
We also need to print position and then match with number array to print associated value.
Plz help