I have a problem where i am trying to swap two arrays so that they switch beginnings.
example: array 1 = (1,2,3,4,5,6,7,8)
and array 2 = (11,12,13,14,15,16,17,18)
i want to end up with the first array being (11,12,13,14,5,6,7,8)
and i want the second array to be (1,2,3,4,15,16,17,18)
but for some reason i end up with 1=(11,12,13,14,5,6,7,8) and 2=(11,12,13,14,15,16,17,18)
my code is provided below, what am i doing wrong?
public static void Mutate(Genetic lowest, Genetic secondLowest) {
int halfway = (lowest.getPopulation().length)/2;
int[] one = lowest.getPopulation();
int[] two = secondLowest.getPopulation();
int[] temp = secondLowest.getPopulation();
int[] temp2 = lowest.getPopulation();
for(int i = 0; i < halfway; i++){
temp[i] = one[i];
}
lowest.setPopulation(temp);
for(int i = 0; i < lowest.getPopulation().length; i++){
System.out.print(temp[i]);
}
System.out.println();
for(int i = 0; i < halfway; i++){
temp2[i] = two[i];
}
for(int i = 0; i < lowest.getPopulation().length; i++){
System.out.print(temp2[i]);
}
}