Selection sort

The problem

The selection-sort method repeatedly finds the smallest number in the current array and swaps it with the first. Rewrite this program by finding the largest number and swapping it with the last. Write a test program that reads in ten double numbers, invokes the method, and displays the sorted numbers.

Breaking it down

static final int MAX_ARRAY_SIZE = 10;

public static void main(String[] args) {

    Scanner input = new Scanner(System.in);
    double[] numbers = new double[MAX_ARRAY_SIZE];

    System.out.print("Enter " + MAX_ARRAY_SIZE + " numbers: ");
    for (int i = 0; i < numbers.length; i++) {
        numbers[i] = input.nextDouble();
    }

    input.close();

    Arrays.stream(numbers).sorted().forEach(e -> System.out.println(e));
}

Output

Enter 10 numbers: 2
4
5
6
2
1
9
7
4
2
---
1.0
2.0
2.0
2.0
4.0
4.0
5.0
6.0
7.0
9.0