Created
December 18, 2012 08:49
-
-
Save hutt/4326259 to your computer and use it in GitHub Desktop.
Sortieralgorithmus (Java)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* | |
* 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