package com.codegym.task.task07.task0728;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
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) {
Arrays.sort(array);
int[] array2 = new int[20];
for (int i = array.length-1; i >= 0; i--) {
array2[array2.length-i-1] = array[i];
}
for (int x : array2) {
System.out.println(x);
}
}
}
Another code that should be passing :)
Under discussion
Comments (5)
- Popular
- New
- Old
You must be signed in to leave a comment
towelie8
27 August 2020, 10:07
public static void sort(int[] array) {
//write your code here
for (int i = 0; i < array.length; i++){
array[i] = array[i] * -1;
}
Arrays.sort(array);
for (int i = 0; i < array.length; i++){
array[i] = array[i] * -1;
}
}
0
Girish Patel
16 October 2019, 18:42
You don't need to print array in sort method print array in main method. And also need to change the sort method.
0
Michael Martin
13 November 2018, 16:49
In your program, you are sorting the passed array in increasing order. You need to sort the array in DECREASING order, not instantiate a new array and sort that one.
+1
Juan Gallardo
14 November 2018, 02:32
But when I make the sort() method return a sorted array, I get an error because the method is supposed to be void!
0
Luis Rodriguez Ugarte
19 September 2019, 12:29
You don't have to print anything in sort method
0