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())
There are three kinds of actuaries: those who can count, and those who can't.
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:
sum([5, 10])=15
sum([5, 10])=15
sum([15])=15
I am trying to figure out how to get the output to print the position of the array:
sum([3]) = 15
sum([0,3)] = 15
sum([1,3)]=15
Phillip Small wrote:That would work as well.
There are three kinds of actuaries: those who can count, and those who can't.
There are three kinds of actuaries: those who can count, and those who can't.
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.
There are three kinds of actuaries: those who can count, and those who can't.
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.
Consider Paul's rocket mass heater. |