I have two data file. Data are double type. File one consist of 3 column and several Rows and File two consist of 4 Column and Several row. I read data from both file separately in one Java program and the Column one data of File1 are matched with the Column one data of File2 then a message will display that data are matched else data are not match. My code is like that
import java.io.File;
import java.util.Scanner;
public class F1 {
public static void main(String args[])throws Exception{
Scanner Y =new Scanner(new File("C:\\R5_M.txt"));
Scanner X =new Scanner(new File("C:\\R5_O.txt"));
double a=0.0,b=0.0,c,d=0.0,e=0.0,f,g,h;
if(a==d) {
while (X.hasNext()) {
a = X.nextDouble();
b = X.nextDouble();
c = X.nextDouble();
}
while (Y.hasNext()) {
d = Y.nextDouble();
e = Y.nextDouble();
f = Y.nextDouble();
g = Y.nextDouble();
}
System.out.println("They are matched");
}
else{
System.out.println("Not Matched");
}
}
}
It's output is They are matched for only one time. But it should write output equal to number of rows. If I have 10 Rows in both data files and 6 data are matched and 4 are not matched then I get a output They are matched for 6 times and Not Matched for 4 times.
One obvious reason is both while loops are end within there scope.So the value that change for a,b,c,d,e,f,g are remain in the scope or should I say they are overwrite in each iteration and if I call a and d outside while loop then it returns only the last value in this case 10th value. So where should I write down the if statement to compare each value?
a == d, which is always will because they haven't been assigned a value yet.