public class Methoden { static double field[]; public static void main(String[] args) { field = new double[100]; int help; int a = 5; int b = 3; System.out.println("a="+a+", b="+b); // swap help = a; a = b; b = help; System.out.println("a="+a+", b="+b); // TODO Auto-generated method stub for (int i=0; i<100; i++) { //System.out.println("f(" + i + ")=" + square(i)); field[i] = Math.random(); } //System.out.println("field[0]="+field[0]+", field[1]="+field[1]); //swap(field, 0, 1); //System.out.println("field[0]="+field[0]+", field[1]="+field[1]); // selection sort for (int i=field.length-1; i>0; i--) { int largestIndex = 0; // search for the largest element for (int j = 0; j<=i; j++) { if (field[j]>field[largestIndex]) { largestIndex = j; } } // swap largest element with last element swap(field, largestIndex, i); } for (int i=0; i<100; i++) { System.out.println("field(" + i + ")=" + field[i]); } } public static double square(double x) { if (x>0){ return x * x; } else{ return x * x; } } public static void swap(double field[], int i, int j) { double temp = field[i]; field[i] = field[j]; field[j] = temp; } }