Ok, I know there is nothing wrong with what I've got(maybe I'm wrong but I doubt it), but it wont compile. It says it can't resolve these two methods:
Collections.sort(int[])
Collections.reverseOrder(int[]);
Code:/* * ReverseArray.java * Created on June 13 */ import java.util.*; /** * @author * @version **/ class ReverseArray { /*Instance variable*/ private int[] intArray; /**Class constructor*/ public ReverseArray() { super(); } /**Get the private instance variable *@return intArray array of ints */ public int[] getArray() { return intArray; } /**Sort and print out the array in ascending order *@param array int[] array *@return void */ public void sortAscending(int[] array) { System.out.println("<---------------Ascending Order-------------->"); Collections.sort(array); for (int i=0; i<array.length; i++) { System.out.println("array[" + i + "]= " + array[i]); } } /**Sort and print out the array in descending order *@param array int[] array *@return void */ public void sortDescending(int[] array) { System.out.println("<---------------Descending Order-------------->"); Collections.reverseOrder(array); for (int i=0; i<array.length; i++) { System.out.println("array[" + i + "]= " + array[i]); } } /**Main method *@param args command line args *@return void */ public static void main(String[] args) { ReverseArray ra = new ReverseArray(); ra.sortAscending(ra.getArray()); ra.sortDescending(ra.getArray()); } }




Reply With Quote