Hallo,
ich verstehe nicht warum bei mir die variablen x und y sortiert werden, obwohl ich für das sortierte Array eine eigene Variable erstellt habe.
Also Beispiel: die Methode "empirischeKovarianz" bekommt den Parameter x und y aber diese sind sortiert und ich weiß nicht warum
Vielen Dank für antworten
ich verstehe nicht warum bei mir die variablen x und y sortiert werden, obwohl ich für das sortierte Array eine eigene Variable erstellt habe.
Also Beispiel: die Methode "empirischeKovarianz" bekommt den Parameter x und y aber diese sind sortiert und ich weiß nicht warum
Vielen Dank für antworten
Java:
public static void main(String[] args) {
double[] y = { 103.54, 88.76, 88.12, 72.37, 65.5, 52.17, 49.40, 46.14, 44.58, 41.93 };
double[] x = {311, 373, 242.4, 125.2, 135.1, 161.6, 106.6, 115.8, 142.9, 83.8 };
double[] sortiert_x = bubblesort(x);
double[] sortiert_y = bubblesort(y);
System.out.println("X Sortiert:" + "\tY Sortiert:");
for (int i = 0; i < sortiert_x.length; i++) {
System.out.println(sortiert_x[i] + "\t\t" + sortiert_y[i]);
}
System.out.println("Sxy: " + empirischeKovarianz(x, y));
}
public static double[] bubblesort(double[] zusortieren) {
double temp;
for (int i = 1; i < zusortieren.length; i++) {
for (int j = 0; j < zusortieren.length - i; j++) {
if (zusortieren[j] > zusortieren[j + 1]) {
temp = zusortieren[j];
zusortieren[j] = zusortieren[j + 1];
zusortieren[j + 1] = temp;
}
}
}
return zusortieren;
}