Need help with array

Discussion in 'Programming General' started by d great one, Jun 24, 2009.

Need help with array
  1. Unread #1 - Jun 24, 2009 at 8:54 AM
  2. d great one
    Joined:
    Nov 4, 2007
    Posts:
    930
    Referrals:
    2
    Sythe Gold:
    0

    d great one Apprentice

    Need help with array

    This is my main program. Everything is fine before calling the method.

    This is the main problem. I don't know how to put mathematical operation in an array.
    The method should sort the input integers.
    In example, if I input 5, 8, 9, 4,6 the method will sort all the integers and display the lowest first then to the highest integer.


    Need help please. Thanks!
     
  3. Unread #2 - Jun 24, 2009 at 8:20 PM
  4. mu-b
    Joined:
    Jun 24, 2009
    Posts:
    1,353
    Referrals:
    2
    Sythe Gold:
    0

    mu-b War is a Drug
    Banned

    Need help with array

    Code:
    public class Sorting
    {
    	public int[] Sorting(int sort)
    	{
    		Array.sort(sort)
    	}
    }
    that should work, unless you need to make you're own method if so, i can try to work something out for you.
     
  5. Unread #3 - Jun 24, 2009 at 8:56 PM
  6. Nullware
    Joined:
    Jan 30, 2007
    Posts:
    1,761
    Referrals:
    4
    Sythe Gold:
    0

    Nullware Guru

    Need help with array

    You should have int[] sort as your parameter..? As you are taking an array of input and just returning it back sorted.
     
  7. Unread #4 - Jun 24, 2009 at 9:28 PM
  8. mu-b
    Joined:
    Jun 24, 2009
    Posts:
    1,353
    Referrals:
    2
    Sythe Gold:
    0

    mu-b War is a Drug
    Banned

    Need help with array

    ya u rite mi bad i was in a rush

    int[] sorted = new int[5]; int compare; for(int x = 0; x< 5; x++) { compare = number[x]; for(int y = 0; y<5; y++){if(compare > number[y]){compare=number[y];} sorted[x] = compare;} }

    i thnk dat shuld sort ur number array into a new sorted array n inkase u kant tel its a bubble sort. it shuld work tho.
     
< help | Java Help / Teaching >

Users viewing this thread
1 guest


 
 
Adblock breaks this site