minimaster123
Enthusiast
Hallöchen!
Ich hab (aus einer Klausur) folgende Codezeilen und hätte gern gewusst (zum Nachvollziehn), warum das rauskommt, was dann da rauskommt.
int hilf;
int [] a = {6,8,2,9,0};
for (int i=0;i<a.length-1;i++)
for (int j = i + 1; j < a.length; j++)
if(a > a[j]) {
hilf = a;
a = a[j];
a[j] = hilf;
}
for (int i = 0; i < a.length; i++)
System.out.print (a + " ");
System.out.println();
Als Ergebnis kommt folgendes raus:
0 2 6 8 9
Für Eure Bemühungen schon mal danke.
Ich hab (aus einer Klausur) folgende Codezeilen und hätte gern gewusst (zum Nachvollziehn), warum das rauskommt, was dann da rauskommt.

int hilf;
int [] a = {6,8,2,9,0};
for (int i=0;i<a.length-1;i++)
for (int j = i + 1; j < a.length; j++)
if(a > a[j]) {
hilf = a;
a = a[j];
a[j] = hilf;
}
for (int i = 0; i < a.length; i++)
System.out.print (a + " ");
System.out.println();
Als Ergebnis kommt folgendes raus:
0 2 6 8 9
Für Eure Bemühungen schon mal danke.
