-1

I am trying to make a array to print everything in reverse order. I get this error:

The error: side535Opg15.java:13: error: cannot find symbol
Arrays(mArray.reverseOrder());
symbol: method reverseOrder()
location: variable mArray of type int[]
1 error

Here is my code:

import java.util.*;

public class side535Opg15{

   public static void main(String[] args){

   int[] a1 = {2,7,6,5,1,9};

   int[] mArray = printBackwards(a1);
   System.out.println(Arrays.toString(mArray));
   Arrays.sort(mArray);
   System.out.println(Arrays.toString(mArray));
   Arrays.sort(mArray.reverseOrder());
   System.out.println(Arrays.toString(mArray));

   }

   public static int[] printBackwards(int[] a1){
      int[] aFinal = new int[a1.length];
      for (int i = 0; i < a1.length; i++){
      aFinal[i]=a1[i];

      }
      return aFinal;
   }
}
Racil Hilan
  • 24,690
  • 13
  • 50
  • 55
  • obvioiusly an array does not have a `reverseOrder()` method. perhaps you meant `java.util.Collections.reverseOrder()`? perhaps you need to google how to sort an array in reverse order? https://www.tutorialspoint.com/java/util/collections_reverseorder.htm – Sharon Ben Asher Oct 09 '16 at 08:47

1 Answers1

-2

You have not written reverseOrder() method that's why you are getting this error.

V. Mishra
  • 61
  • 4
  • that is not the problem. well, technically it is, but how do you suggest OP writes a method for an immutable java.lang class ?? if OP wants to sort an array in reverse order, there is a way to do it in Java, and it does not involve writing a method for `array` – Sharon Ben Asher Oct 09 '16 at 08:49
  • you can implement comparator interface to provide sorting logic. – V. Mishra Oct 09 '16 at 08:52
  • ex: Arrays.sort(mArray,Comparator). – V. Mishra Oct 09 '16 at 08:53
  • thanks very much. but once again, sorting an array in reverse natural order of elements does not require implementing a Comparator – Sharon Ben Asher Oct 09 '16 at 08:56