SHOW:
|
|
- or go back to the newest paste.
| 1 | - | public static int getAllSums(int array[], int startingValue, int pos, int target){ |
| 1 | + | public static int getAllSums(int array[], int startingValue, int pos, int target){
|
| 2 | - | |
| 2 | + | |
| 3 | - | int random = 0; |
| 3 | + | int random = 0; |
| 4 | - | int sum1 = random; |
| 4 | + | int sum1 = random; |
| 5 | - | |
| 5 | + | |
| 6 | - | for (int i = pos; i < array.length; i++) |
| 6 | + | for (int i = pos; i < array.length; i++) |
| 7 | - | { |
| 7 | + | {
|
| 8 | - | int currentValue = startingValue + array[i]; |
| 8 | + | int currentValue = startingValue + array[i]; |
| 9 | - | |
| 9 | + | |
| 10 | - | |
| 10 | + | |
| 11 | - | |
| 11 | + | |
| 12 | - | if(currentValue%target == 0) { |
| 12 | + | if(currentValue%target == 0) {
|
| 13 | - | |
| 13 | + | |
| 14 | - | array[i] = 0; |
| 14 | + | array[i] = 0; |
| 15 | - | sum1 = random + currentValue; |
| 15 | + | sum1 = random + currentValue; |
| 16 | - | |
| 16 | + | |
| 17 | - | return sum1; |
| 17 | + | return sum1; |
| 18 | - | }else { |
| 18 | + | }else {
|
| 19 | - | |
| 19 | + | |
| 20 | - | getAllSums(array, currentValue, i + 1, target); |
| 20 | + | getAllSums(array, currentValue, i + 1, target); |
| 21 | - | |
| 21 | + | |
| 22 | - | } |
| 22 | + | } |
| 23 | - | |
| 23 | + | |
| 24 | - | } |
| 24 | + | } |
| 25 | - | return 0; |
| 25 | + | return 0; |
| 26 | - | |
| 26 | + | |
| 27 | - | |
| 27 | + | |
| 28 | } |