Skip to content

Instantly share code, notes, and snippets.

@hutt
Created December 18, 2012 08:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hutt/4326259 to your computer and use it in GitHub Desktop.
Save hutt/4326259 to your computer and use it in GitHub Desktop.
Sortieralgorithmus (Java)
/**
*
* Nope.
*
* @version 1.0 vom 18.12.2012
* @Jannis Hutt
*/
import java.io.*;
public class sort12zufall {
public static void main(String[] args) throws IOException {
//EINGABE
long zahl[] = new long [12];
for (int k=0;k<12 ;k++ ) {
zahl[k] = Math.round(Math.random()*11+1); //Zufallszahl generieren
} // end of for
long hilf = 0;
System.out.println("Anfangszahlen: ");
for (int l=0; l<12; l++) {
System.out.print(zahl[l] + " ");
} // end of for
//VERARBEITUNG
for (int j=0; j<12; j++) {
for (int i=0; i<11; i++) {
if ( zahl[i] > zahl[i+1] ) {
hilf = zahl[i];
zahl[i] = zahl[i+1];
zahl[i+1] = hilf;
} // end of if
} // end of for
} // end of for
//AUSGABE
System.out.println("\n\nAusgabezahlen: ");
for (int m=0; m<12; m++) {
System.out.print(zahl[m] + " ");
} // end of for
} // end of main
} // end of class sort4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment