Hello friends am trying to create a java program to sort an array in ascending and descending order
here is the program I created
import java.util.Arrays;
import java.util.Collections;
public class ArraySort
{
public static void main(String [] args)
{
int [] num = {5,9,1,65,7,8,9};
Arrays.sort(num);
System.out.println("The rsorted array in ascending order");
for(int i = 0; i<num.length; i++)
{
System.out.println(num[i]);
}
System.out.println("The rsorted array in descending order");
Arrays.sort(num,Collections.reverseOrder(num));
for(int i = 0; i<num.length; i++)
{
System.out.println(num[i]);
}
}
}
BUT I GET THE FOLLOWING EROOR ON COMPILATION
ArraySort.java:12: error: no suitable method found for reverseOrder(int[])
Arrays.sort(num,Collections.reverseOrder(num));
^
method Collections.<T#1>reverseOrder(Comparator<T#1>) is not applicable
(no instance(s) of type variable(s) T#1 exist so that argument type int[] conforms to formal parameter type Comparator<T#1>)
method Collections.<T#2>reverseOrder() is not applicable
(cannot instantiate from arguments because actual and formal argument lists differ in length)
where T#1,T#2 are type-variables:
T#1 extends Object declared in method <T#1>reverseOrder(Comparator<T#1>)
T#2 extends Object declared in method <T#2>reverseOrder()
1 error
What's wrong with my program? Suggest a solution for me