Java -> Sort in Descending order

Status
Not open for further replies.

Axehack

In Runtime
Messages
110
Location
http:\\www
This is the code I have:


Code:
import java.io.*;
public class TutQ4
{
  public static int getMark(int counter,String x) throws IOException
    {
    int n=0;
      System.out.print("Please enter a mark for exam for "+x+" :");
      n=DSInput.readInt();
    return(n);
    }
   public static String getName(int counter) throws IOException
    {
    String x;
      System.out.print("Please enter a name "+counter+":");
      x=DSInput.readString();
    return(x);
    }
 public static void printResults(String printName[],int printMark[]) throws IOException
    {
    for (int counter=0;counter<5;counter++)
      {
      System.out.println(printName[counter]+" scored "+printMark[counter]);
      }
    }
    public static void pause() throws IOException
    {
    System.out.println("\nPress any key to continue");
    String dummy = DSInput.readString();
    }

  public static void main(String argv[]) throws IOException
    {
   int[] numbers;
   numbers = new int[5];
   String[] names;
   names = new String[5];
    for (int counter=0;counter<5;counter++)
      {
      names[counter] = getName(counter);
      numbers[counter] = getMark(counter,names[counter]);
      }
 
 
    printResults(names,numbers);
    pause();
    }
}


I need to get the array do print grouped by Mark in descending order
 
We can't help you with your homework however I will give you a couple of pointers.

What you have so far is a very strange way of going about it. One of the problems that it presents you is that there are two arrays being passed into the printing function.
Sorting arrays, lists and collections is a very common requirement; if you find that you are having to do a lot of work to get it right, you've probably gone wrong somewhere.
 
Well I dont actually know any java, so this is not my area of expertise... I was just hoping someone could tell me how to do it, which would beter my understanding of the language... we all have to start somewhere... But thanks anyway i guess..
 
Status
Not open for further replies.
Back
Top Bottom