Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

java error

  • 21-11-2002 07:13PM
    #1
    Closed Accounts Posts: 232 ✭✭


    hi
    im writing a program in college that get the position of where someone came in their class
    i have a class student that has name score and position
    im trying to go through the array of objects to determine each student position in the class but it doesnt seem to be working
    any help would much appreciated
    maybe im using the wrong approach
    for(int i=0; i<sizeX; i++)
    {
    int count = i+1;
    for(int k=0; k<sizeX; k++)
    {
    while(A.score < A[k].score)
    count++;
    }
    A.pos = count;
    }
    for(int p=0; p<sizeX; p++)
    System.out.println(A[p].pos + ", " + A[p].name);


Comments

  • Closed Accounts Posts: 232 ✭✭red vex


    actually that while loop shud b an if statement
    help me jebus


  • Registered Users, Registered Users 2 Posts: 2,281 ✭✭✭DeadBankClerk


    [php]
    // Bubble sort students
    // Biggest score 'bubbles' all the way to
    // the top during each iteration of the j-loop
    // This is the slowest possible way to do it
    Student temp; // A temp storage for swaps
    for (int i = 0; i < a.length; i++)
    {
    for (int j = a.length-1; j > i; j--)
    {
    if (a[j-1].score < a[j].score)
    {
    temp = a[j-1];
    a[j-1] = a[j];
    a[j] = temp;
    }
    }
    a.pos = i + 1;
    System.out.println(A[p].pos + ", " + A[p].name);
    }
    [/php]

    There you go, homework done =)
    I have no problem helping anyone who posts up an attemt that they have made. Time for Jazz to make me look silly now...


Advertisement