Results 1 to 3 of 3
  1. #1
    bodyzsoul is offline Member
    Join Date
    Nov 2014
    Posts
    1
    Rep Power
    0

    Question Adding X consecutive values in an array and getting the minimal value!

    Hello there :)
    This is my first post on this amazing forum, I wish I can find help from the amazing java developers here :D

    Here is my problem:

    if I want to add a number of X consecutive values in an array and get the minimal total value along with the indexes that caused this result, how can I do that?

    for example:

    X = 2
    array[4] = (5,2,8,6,7)

    start adding every 2 consecutive values as following:

    array[0]+array[1] = 5+2 = 7 //minimal value
    array[1]+array[2] = 2+8=10
    array[2]+array[3] = 8+6= 14
    array[3]+array[4] = 6+7=13

    output:
    minimal value = 7
    indexes of minimal values are: 0 and 1

    Thank you in advance! :D

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: Adding X consecutive values in an array and getting the minimal value!

    First, I recommend you simply try and find the minimum value of an array and its index. If you aren't sure how to program it, then try to do it on paper first. Once you figure that out, the solution to your posted task should be apparent.


    Edit: Duh, I meant to say minimum value earlier. In any event, the algorithms are practically identical.

    Regards,
    Jim
    Last edited by jim829; 11-09-2014 at 10:36 PM.
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  3. #3
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,807
    Rep Power
    12

Similar Threads

  1. Stack is adding same values.
    By coolman50544 in forum New To Java
    Replies: 3
    Last Post: 06-16-2014, 09:43 PM
  2. Help adding array values.
    By Kirstielol in forum New To Java
    Replies: 4
    Last Post: 03-20-2012, 07:42 PM
  3. Replies: 1
    Last Post: 04-05-2011, 09:58 PM
  4. Replies: 14
    Last Post: 01-22-2011, 03:36 PM
  5. Adding Values of 2 Arrays
    By core2duo5252 in forum Java 2D
    Replies: 7
    Last Post: 09-05-2009, 04:50 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
  •