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 6 of 6

Thread: Need help with my findMin method. Code included

  1. #1
    Junior Member
    Join Date
    Sep 2013
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Need help with my findMin method. Code included

    Im suppose to perform this method recursively however when I lauch the program i get an error stating out of bounds. Any suggestions?
    // assumes that a != null && a.length > 0
    public static int findMin(int[] a) {
        return findMinRecursive(a, a[0], 1);
    }
     
    private static int findMinRecursive(int[] array, int lo, int pos) {
        if(pos >= array.length)
            return lo;
     
        if(array[pos] < lo)
            lo = array[pos];
     
        return findMinRecursive(array, lo, pos + 1);
    }


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Need help with my findMin method. Code included

    What's out of bounds? Post the exact error message and stack trace, copied and pasted into a post.

  3. #3
    Junior Member
    Join Date
    Sep 2013
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Need help with my findMin method. Code included

    Quote Originally Posted by GregBrannon View Post
    What's out of bounds? Post the exact error message and stack trace, copied and pasted into a post.
    It was along the lines of an Exception such as an IllegalArgumentException at line 3 saying out of bounds

  4. #4
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Need help with my findMin method. Code included

    When you can post an exact copy of the error message rather than your best guess/recollection, do that.

  5. #5
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Need help with my findMin method. Code included

    My car kinda makes a funny noise. Do you think the mechanic will be able to fix it?
    Improving the world one idiot at a time!

  6. #6
    Member
    Join Date
    Sep 2013
    Posts
    68
    My Mood
    Confused
    Thanks
    3
    Thanked 7 Times in 7 Posts

    Default Re: Need help with my findMin method. Code included

    This code is perfectly fine buddy.

Similar Threads

  1. Replies: 7
    Last Post: April 25th, 2013, 01:12 PM
  2. Replies: 1
    Last Post: January 23rd, 2013, 07:29 AM
  3. Replies: 5
    Last Post: July 24th, 2012, 12:37 AM
  4. [SOLVED] Printwriter class: displaying File contents to screen with included formatting?
    By mwebb in forum File I/O & Other I/O Streams
    Replies: 10
    Last Post: November 25th, 2011, 11:38 AM
  5. JDBC code not included into JAR file??
    By friday in forum JDBC & Databases
    Replies: 4
    Last Post: December 17th, 2010, 12:32 PM