I am beginner to java coding, I am facing some complexity in updating the array.
My problem is I have an array named s1[]
which consists of 10 elements from that I have to choose 1st 3 elements and I have to store in one array i.e. max1[]
array and in next array I have to choose randomly 3 elements from the same array i.e. s1[]
and store it in max6[]
and I need to do comparison between the two arrays i.e. max1[]
and max6[]
so that the matching values will be stored.
My code looks like this (here f1 = 3
)
for (i1 = 0; i1 < f1; i1++) {
max1[i1] = s1[i1];
System.out.println("1st tree random leaf nodes of phy m/c 1 at tree 1 : " + max1[i1]);
System.out.println(" \n ");
max6[i1] = s1[(int) (Math.random() * f1)];
System.out.println(" random leaf nodes of phy m/c 1 at tree 2: " + max6[i1]);
System.out.println(" \n ");
}
for (int l1 = 0; l1 < f1; l1++) {
for (int k1 = 0; k1 < f1; k1++) {
if (max1[l1] == max6[k1]) {
c1[l1] = max1[l1];
k1++;
System.out.println("the value after crossover is:--------->" + c1[l1]);
break;
}
}
}
now what I want is that I have to repeat the loop for some iterations so that in the next iteration the values of the max1
array in 1st iteration shouldn't be repeated means I have to permanently remove the elements from s1
array until s1
array contains zero elements in it