It keeps on giving feedback that the sort method should be able to sort an array of any length.. even though that is NOT in the required Conditions. So I have modified it so that it could actually sort any length array and it still won't verify.
So I am lost.
package com.codegym.task.task08.task0826;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
/*
Five winners
Create an array of 20 numbers.
Populate it with numbers from the keyboard.
Display the five largest numbers.
Each value should be on a new line.
Requirements:
1. The program should display numbers on the screen.
2. The program should read values from the keyboard.
3. The Solution class must have two methods.
4. The sort() method should sort the array of numbers from highest to lowest.
5. The main() method should call the sort() method.
6. The program should display the five largest numbers in the array. Each value should be on a new line.
*/
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);
int[] array2 = new int[20];
for( int i = 0, j = (array.length - 1); i < (array.length); i++, j--){
array2[j] = array [i];
}
for (int i = 0; i < array.length; i++)
array[i] = array2[i];
}
}