Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

java error

Options
  • 21-11-2002 7: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 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