double[] temp = new double[rows]; // temp points to a new array
temp = totalCO2; // now you point to the array, totalCO2 points to
double[] sortedTotalCO2=SelectionSort(temp); // this function modifies the array temp, which is equal to the array totalCO2 points to
To fix this, change the SelectionSort(temp)
method as following:
private static double[] SelectionSort(double[] b) {
double[] a = new double[b.length];
System.arraycopy(b, 0, a, 0, b.length);
int min=-1;
for (int i = 0; i < a.length; i++) {
min = i;
for (int j = i + 1; j < a.length; j++) {
if (a[min] > a[j]) {
min = j;
}
}
if (min != i) {
double temp = a[min];
a[min] = a[i];
a[i] = temp;
}
}
return a;
}
Remove the lines:
double[] temp = new double[rows];
temp = totalCO2;
and change this line as following:
double[] sortedTotalCO2=SelectionSort(totalCO2);