Advertisement
Zidinjo

Untitled

Dec 7th, 2014
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.14 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class aahilfe
  4. {
  5.     public static void main(String[] args)
  6.     {
  7.         System.out.println("Wie viele Werte möchten sie eingeben?");
  8.         Scanner eingabe = new Scanner (System.in);
  9.         int anzahlDerWerte = eingabe.nextInt();
  10.         System.out.println("Geben Sie nun den Wert / die Werte ein:");
  11.         double[] unsort = new double[anzahlDerWerte];
  12.         for (int i = 0; i < anzahlDerWerte; i++)
  13.         {
  14.             unsort[i] = eingabe.nextDouble();
  15.         }
  16.         sortArray(unsort);
  17.     }
  18.    
  19.     static void sortArray (double[] unsort)
  20.     {
  21.         double[] sort = unsort.clone();
  22.        
  23.         double zwischenspeicher = 0.0;
  24.        
  25.         for (int i = 0; i < sort.length; i++)
  26.         {
  27.            
  28.             for (int a = i+1; a < sort.length ; a++)
  29.             {
  30.                 if (sort[i] > sort[a])
  31.                 {
  32.                     zwischenspeicher = sort[i];
  33.                     sort[i] = sort[a];
  34.                     sort[a] = zwischenspeicher;
  35.                 }
  36.                
  37.             }
  38.             System.out.println(sort[i]);
  39.         }
  40.     }
  41.  
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement