Hi all,
I wrote my code a few different ways and they all seem to work but they just aren't satisfying the conditions. If you copy and paste my code into intelliJ and try it for yourself it seems to be working..
Does anyone know why this isn't satisfying the codegym conditions?
Thanks!
package com.codegym.task.task07.task0728;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
/*
In decreasing order
Task: Write a program that reads 20 numbers from the keyboard and displays them 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);
for (int x : array) {
System.out.println(x);
}
}
public static void sort(int[] array) {
//write your code here
int j = 0;
int[] tempArray = new int[20];
Arrays.sort(array);
for (int i = 19; i >= 0; i--) {
tempArray[j] = array[i];
j++;
}
array = tempArray;
}
}