I understand that just assigning reversearray to array doesn't work. So I googled and found clone() method. But it still doesn't work. If I display the result of array inside sort method it displays numbers in descending order. But in the main method, it displays in ascending order.
I KNOW how to pass the task. That is NOT my question. I'm wondering WHY clone() method does not work in my code.
Thank you in advance.
package com.codegym.task.task07.task0728;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Collections;
/*
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
Arrays.sort(array);
int[] reversearray = new int[20];
for (int i = 0; i < array.length; i++){
reversearray[20 - i - 1] = array[i];
}
array = reversearray.clone();
}
}