# Thread: Adding X consecutive values in an array and getting the minimal value!

1. Member
Join Date
Nov 2014
Posts
1
Rep Power
0

## 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

2. Senior Member
Join Date
Jan 2013
Location
Northern Virginia, United States
Posts
6,226
Rep Power
14

## 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.

3. ## Re: Adding X consecutive values in an array and getting the minimal value!

#### Posting Permissions

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