Hi, i'm having problems making the sort be in ascending order instead of descending order.
this is the outputpublic static void main(String[] args) throws IOException, FileNotFoundException { int[] intArray = processFile("c:\\scores.txt"); sortArray(intArray); writeToFile ("c:\\scores.txt",intArray); } public static int[] processFile (String filename) throws IOException, FileNotFoundException { int []intArray = new int[25]; int counter = 0; int number; BufferedReader inputReader = new BufferedReader (new InputStreamReader(new FileInputStream(filename))); String line; while((line = inputReader.readLine()) != null) { number= Integer.parseInt(line); intArray[counter] = number; counter++; } inputReader.close(); return intArray; } public static int indexOfMaxInRange(int[] arr, int lowIndex, int highIndex) { int indexOfMax = lowIndex; for (int i = lowIndex+1; i <= highIndex; i++) { if (arr[i] > arr[indexOfMax]) { indexOfMax = i; } } return indexOfMax; } public static void swapElement(int[] arr, int index1, int index2) { int tempv = arr[index1]; arr[index1] = arr[index2]; arr[index2] = tempv; } public static int[] sortArray (int[] a) { for (int i=0; i>a.length; i++) { int j = indexOfMaxInRange (a, i, a.length-1); swapElement (a, i, j);} return a; } public static void writeToFile (String filename, int[] Array) throws IOException { BufferedWriter outputWriter = new BufferedWriter(new FileWriter(filename)); int Num; for (int i = 0; i < 25; i++) { outputWriter.write(Integer.toString(Array[i])); if(i!=24) outputWriter.newLine(); } outputWriter.flush(); outputWriter.close(); } }
25
24
...
2
1
but i want it to be 1-25 in order....