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.

Arranging An Array In Java

  • 14-03-2003 10:16AM
    #1
    Registered Users, Registered Users 2 Posts: 483 ✭✭


    Hi,

    Just a quick question that's probably easily answered. Ok, I've got a program and in it, a user enters in a series of numbers (results in this case) which are stored in an array. What I want to know is, how can i arrange this array in ascending order? I'm relatively new to Java, so please, be gentle.


Comments

  • Registered Users, Registered Users 2 Posts: 1,931 ✭✭✭Zab


    Have a look at the class java.util.Arrays.

    Zab.


  • Registered Users, Registered Users 2 Posts: 7,468 ✭✭✭Evil Phil


    and do you own fecken homework :mad:


  • Closed Accounts Posts: 1,651 ✭✭✭Enygma


    Take a look at the article on comparing objects on http://www.onjava.com at the moment.
    very informative.


  • Registered Users, Registered Users 2 Posts: 683 ✭✭✭TenLeftFingers


    Good link Enygma, there's stuff there I can use on my project :)


  • Closed Accounts Posts: 741 ✭✭✭michaelanthony


    Do a *******ort


  • Advertisement
  • Closed Accounts Posts: 741 ✭✭✭michaelanthony


    Do a Bubble sort


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


    [php]
    float result_array [];

    // enter values into array

    float temp;
    for (int i = 0; i < result_array.length - 1; i++)
    for (int j = i + 1; j < result_array.length; j++)
    if (result_array[j] > result_array)
    {
    temp = result_array;
    result_array = result_array[j];
    result_Array[j] = temp;
    }
    [/php]


  • Registered Users, Registered Users 2 Posts: 19,396 ✭✭✭✭Karoma


    look up sorts (bubble,quick,etc.) on java.sun.com & see demo's in C:\j2sdkfolder\demo\applets


Advertisement