I have a two dimensional array that contains integers ranging from 1 to 9. What I'm trying to do is in each row go through it and add up each number to 20 and print out a new array with those numbers. If a number used makes it so that it does not equal 20 that number is now 0. for an example:

And welcome to the Ranch
There is a mistake in the first thing you wrote. You don’t have a 2D array; there ain’t no such critter in Java. You have an array of arrays, (which is actually better than a 2D array).

Andrew Harry wrote:
I can't for the life of me think of an algorithm that would come up with a correct answer.

Having read this topic three times, I still can't figure out what you are trying to say. Perhaps if you can better describe the algorithm, so that we can understand it, then they can be translated to pseudo code, which can be used to translate to actual code.

Andrew Harry wrote:
I can't for the life of me think of an algorithm that would come up with a correct answer.

Having read this topic three times, I still can't figure out what you are trying to say. Perhaps if you can better describe the algorithm, so that we can understand it, then they can be translated to pseudo code, which can be used to translate to actual code.

Ohhh.... I see.

The algorithm looks pretty straightforward. Start at index zero. At the current index, count forward until you either you get 20, or exceed 20. If you get 20, then mark the whole range (of all the involved numbers). And here is the trick, even though a number is marked, you don't get to skip it. You still need to only go one index at a time, as any number can be marked more than once, as part of different ranges.