I try to implement some code block.I have four array.
double[]timea={1.0,2.0,3.0,4.0,5.0,6.0};
double[]speed={11.0,12.0,8.0,13.0,9.0,6.0};
double[]timeb={1.5,2.5,4.0,5.5};
double[]speedb={12.3,8.5,6.9,7.8};
1st array define some time say time stamp and some relative speed corresponding each time block.
Like in time 1.0 speed is 11.0,in time 2.0 speed is 12.0,in time 3.0 speed is 8.0.... etc.
3rd array define timestamp b with some corresponding speed. Like at time 1.5 speed is 12.3, at time 2.5 speed is 3.8, at time 4.0 speed is 5.6 ...etc
I want to write down a program which merge those time and there speed with respect to time.
So the desire output will be
1.0 11.0
1.5 12.3
2.0 12.0
2.5 8.5
3.0 8.0
4.0 13.0
4.0 6.9
5.0 9.0
5.5 7.8
6.0 6.0
I write down a code for that
public class Check {
public static void main(String args[]){
Matrix abc=new Matrix(10,2);
double[]timea={1.0,2.0,3.0,4.0,5.0,6.0};
double[]speed={11.0,12.0,8.0,13.0,9.0,6.0};
double[]timeb={1.5,2.5,4.0,5.5};
double[]speedb={12.3,8.5,6.9,7.8};
int k=0,k1=0;
while(k<timea.length){
abc.set(k, 0, timea[k]);
abc.set(k, 1, speed[k]);
if(timea[k]<timeb[k1]){
abc.set(k,0,timeb[k1]);
abc.set(k,1,speedb[k1]);
if(k1<timeb.length-1){
k1++;
}
}
else if(timea[k]>timeb[k1]){
abc.set(k,0,timea[k]);
abc.set(k,1,speed[k]);
}
k++;
}
abc.print(3,6);
}
}
Program output:
1.500000 12.300000
2.500000 8.500000
4.000000 6.900000
5.500000 7.800000
5.500000 7.800000
6.000000 6.000000
0.000000 0.000000
0.000000 0.000000
0.000000 0.000000
0.000000 0.000000
So please help me to find out the logical error.