Is it a problem that the sort method also prints out the array? Because I can't find any other way if the method is void.
package com.codegym.task.task07.task0728;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;
/*
In decreasing order
*/
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 < 20; i++) {
array[i] = Integer.parseInt(reader.readLine());
}
sort(array);
}
public static void sort(int[] array) {
ArrayList<Integer> numbers = new ArrayList<Integer>();
for(int x : array) {
numbers.add(x);
}
Collections.sort(numbers);
Collections.reverse(numbers);
array = new int[array.length];
int i = 0;
for(Integer value : numbers) {
array[i++] = value;
}
for (int x : array) {
System.out.println(x);
}
}
}