Why it does not work?
When I used (commented) IntStream it has an additional error "The solution class must have two methods.".
I check some data from keyboard manually and it sorts it well, so where is my mistake?
package com.codegym.task.task08.task0826;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
/*
Five winners
*/
public class Solution {
public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int[] array = new int[20];
for (int i = 0; i < array.length; i++) {
array[i] = Integer.parseInt(reader.readLine());
}
sort(array);
System.out.println(array[0]);
System.out.println(array[1]);
System.out.println(array[2]);
System.out.println(array[3]);
System.out.println(array[4]);
}
public static void sort(int[] array) {
Arrays.sort(array);
// IntStream.range(0, 5)
// .forEach(index -> {
// int temp = array[index];
// array[index] = array[array.length - (index + 1)];
// array[array.length - (index + 1)] = temp;
// });
for (int i = 0; i < 5; i++) {
int temp = array[i];
array[i] = array[array.length - (i + 1)];
array[array.length - (i + 1)] = temp;
}
}
}