So, your recursive method will include something like this:-
I am not adding this List, but I know that the sum is equal to the first element plus the sum of the List with its first element removed. But eventually I shall get a lsit with all its elements removed; I shall say that is my base case and give you a default sum of 0.
I shall therefore leave it to you to avoid the risk of lines too long when you complete my code suggestion.
A few minutes ago, I wrote:. . . you have been taught to indent code properly. . . .
or shorter '.mapToInt(i -> i)'
Campbell Ritchie wrote:(...) .mapToInt(i -> i.intValue())
jshell wrote:jshell> System.out.println(List.of(5, 5, 10, 15).subList(1, 4));
[5, 10, 15]
Phillip Small wrote:
The current output is:
I am trying to figure out how to get the output to print the position of the array:
sum() = 15
sum([0,3)] = 15
Phillip Small wrote:That would work as well.
Junilu wrote:I think OP deserves a cow or some pie just for giving us a nice little puzzle to play around with. I don't know if I've seen this one before actually.
Junilu Lacar wrote:I think OP deserves a cow or some pie just for giving us a nice little puzzle to play around with. I don't know if I've seen this one before actually.
Phillip Small wrote:That makes logical sense. You make it sound easy. This thing is killing me. Thanks for your assistance. Maybe, I should just start over.