Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: can't figure out how to sort an array.

  1. #1
    Junior Member
    Join Date
    Jan 2010
    Location
    norcross, ga
    Posts
    24
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default can't figure out how to sort an array.

    help! i can't figure out to sort an array. i think you're supposed to do it like this:

    public int centeredAverage(int[] nums) 
    {
        sort([nums.length - 2] sortedList);
        int sum = 0;
        for (int i = 1; i < nums.length - 1; i++)
        {
           sum = sum + nums[i];
           sortedList = sort[nums];
        }
        int average = sum / sortedList.length;
        return average;
    }


    what have i done wrong here? it won't compile


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: can't figure out how to sort an array.

    Where is your sort method defined? If you don't need to implement your own sorting method, just use Arrays Sort Method

  3. #3
    Junior Member
    Join Date
    Feb 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: can't figure out how to sort an array.

    The first responder is correct, but I hope you're not forced to use a JDK release as old as JDK 1.4.2. This is a link to a more recent version: http://java.sun.com/javase/6/docs/api/java/util/Arrays.html#sort%28int[]%29

Similar Threads

  1. How to Sort an Array using the java.util.Arrays class
    By JavaPF in forum Java SE API Tutorials
    Replies: 2
    Last Post: May 17th, 2014, 01:16 AM
  2. Help with Sort arrays
    By drk in forum Collections and Generics
    Replies: 5
    Last Post: September 6th, 2009, 02:48 AM
  3. simple problem w/ appelets which i cant figure out
    By JavaGreg in forum Java Applets
    Replies: 7
    Last Post: August 15th, 2009, 07:22 PM
  4. Generation of Palindrome number in Java
    By tina.goyal in forum What's Wrong With My Code?
    Replies: 3
    Last Post: May 26th, 2009, 08:49 AM
  5. [SOLVED] Java program to prompt and display the user input number as odd or even
    By napenthia in forum Java Theory & Questions
    Replies: 11
    Last Post: April 22nd, 2009, 01:19 AM