Ich habe jetzt weiter nochmal etwas dran rumprobiert... :
Code:
package sortierenen;
import java.lang.Math;
public class Code {
public void Bubblesort() {
//Zahlenfeld und Zahlen erstellen
int[] Array = new int[5];
for (int i = 0; i < Array.length; i++) {
Array[i] = (int) (Math.random()*100);
System.out.print("ungeordnet" +Array[i]+" ");
System.out.println("");
}
//Sortieren
for (int j=Array.length-1;j>0;j--){
for (int i=0;i<j;i++){
if (Array[i]>Array[i+1]){
int temp=Array[i];
Array[i]=Array[i+1];
Array[i+1] = temp;
System.out.println(+Array[i]+" ");
}
}
}
}
}
Ich habe eine Klammer falsch gesetzt nach dem füllen des Arrays...
Jetzt sieht meine ausgabe halt wie folgt aus ...
"
ungeordnet12
ungeordnet53
ungeordnet66
ungeordnet41
ungeordnet31
41
31
41
31
31
"
Das Array erstellen klappt also soweit schonmal , nur wie kann ich es änders das die Zahlen auch geordnet rauskommen und sich nicht doppeln wie hier gerade der Fall ist??