Results 1 to 7 of 7
  1. #1
    davie89's Avatar
    davie89 is offline Member
    Join Date
    Mar 2012
    Location
    turkey,izmir
    Posts
    5
    Rep Power
    0

    Default help on this method pls

    how can write a method minGap that accepts an integer array as a parameter and returns the mininum difference between adjacent values in the array. i really need ur help on an array or amingap. thanx

    package arrayvalue;

    public class MinimumGap {

    public static void main(String[] args) {
    int[] array = { 1, 3, 6, 7, 12};


    for(int i=1;i<array.length; i++){
    int gap = array[i] - array[i-1];
    System.out.printf("Gap is : %d ( %d - %d ) = %d\n" ,i,array[i],array[i-1],gap);
    }
    }

    public static void mingap() {



    }
    }

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: help on this method pls

    First I think that you will want to show us your attempt to solve it. Else how will we know what needs correcting?

  3. #3
    davie89's Avatar
    davie89 is offline Member
    Join Date
    Mar 2012
    Location
    turkey,izmir
    Posts
    5
    Rep Power
    0

    Default Re: help on this method pls

    i tried and i am stuck there i failed to get the method of minimum please help

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: help on this method pls

    Quote Originally Posted by davie89 View Post
    i tried and i am stuck there i failed to get the method of minimum please help
    Come on now, you need to at least try, or else failing that explain in detail just what you don't understand. Else this is nothing short of a homework dump and that doesn't go over well here.

    You can find out more on how to write methods here:

  5. #5
    davie89's Avatar
    davie89 is offline Member
    Join Date
    Mar 2012
    Location
    turkey,izmir
    Posts
    5
    Rep Power
    0

    Default Re: help on this method pls

    ok thanx i do stand u but just know i am stuck on how to cod the minum array

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: help on this method pls

    Quote Originally Posted by davie89 View Post
    ok thanx i do stand u but just know i am stuck on how to cod the minum array
    Please use standard English here and avoid unnecessary and non-standard abbreviations. For many here English is not their primary language, and so why make things more difficult for them? Also others will respect you more for the attempt.

  7. #7
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: help on this method pls

    As for the minimum array, you don't. Your method gets passed an array, and you loop through the array, checking the differences between the (i) item with the (i+1) item and seeing if it is less than the current minimum. If it is, you replace the current minimum with this new value. Then after the loop ends, return the minimum. Simple.

Similar Threads

  1. Replies: 1
    Last Post: 10-17-2011, 01:00 AM
  2. Declaring a method inside a method: Runnable?
    By africanhacker in forum New To Java
    Replies: 8
    Last Post: 03-23-2011, 04:30 AM
  3. Turning Recursion Method into Iterative method
    By mattakuevan in forum New To Java
    Replies: 9
    Last Post: 06-15-2010, 06:46 AM
  4. Replies: 2
    Last Post: 03-26-2010, 05:12 PM
  5. cannot call private method from static method
    By jon80 in forum New To Java
    Replies: 3
    Last Post: 05-07-2008, 08:37 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •