Beispiel (Benutzereingaben in grün):
Ausgabe: Unsortiert: [16,14,7,6,1,13,12,9,3,0]
Ausgabe: Sortiert: [0,1,3,6,7,9,12,13,14,16]
Ausgabe: Welche positive ganze Zahl wollen Sie dem Array hinzufügen?
Eingabe: 15
Ausgabe: 16 wurde mit 15 ersetzt.
Ausgabe: Sortiert mit neuem Element: [0,1,3,6,7,9,12,13,14,15]
Hallo, ich habe das Programm bis zur Benutzereingabe fertig, dort komme ich nicht mehr weiter. Hat jemand einen Tipp?
Ausgabe: Unsortiert: [16,14,7,6,1,13,12,9,3,0]
Ausgabe: Sortiert: [0,1,3,6,7,9,12,13,14,16]
Ausgabe: Welche positive ganze Zahl wollen Sie dem Array hinzufügen?
Eingabe: 15
Ausgabe: 16 wurde mit 15 ersetzt.
Ausgabe: Sortiert mit neuem Element: [0,1,3,6,7,9,12,13,14,15]
Hallo, ich habe das Programm bis zur Benutzereingabe fertig, dort komme ich nicht mehr weiter. Hat jemand einen Tipp?
Java:
import java.util.Random;
public class Array {
public static void main(String[] args) {
int zufallsZahlen[] = new int[10];
int z=0;
int tobeSorted = 0;
int benutzerEingabe = 0;
System.out.print("Unsortiert: [");
for(int i=0;i<zufallsZahlen.length;i++){
zufallsZahlen[i] = (int) (Math.random()*20);
tobeSorted=zufallsZahlen[i];
z=i-1;
if(i==zufallsZahlen.length-1){
System.out.print(zufallsZahlen[i]);
}
else{
System.out.print(zufallsZahlen[i]+",");
}
while(( z >=0) && (tobeSorted < zufallsZahlen[z])){
zufallsZahlen[z+1] = zufallsZahlen[z];
z= z-1;
}
zufallsZahlen[z+1] = tobeSorted;
}
System.out.println("]");
System.out.print("Sortiert: [");
for(int i=0; i<zufallsZahlen.length; i++){
System.out.print(zufallsZahlen[i]+",");
}
System.out.println("]");
System.out.print("Welche positive ganze Zahl wollen Sie dem Array hinzufügen?");
benutzerEingabe=Input.readInt();
if(benutzerEingabe>=0 && benutzerEingabe<=zufallsZahlen[9]){
}
}
}