I attempted to create a method which calculates the sum of the values of another method in the same way the capital sigma notation does in math. I wanted it to use successive natural numbers as input variables for the function and use recursion to sum it all up. However, as I wanted to create a method for general summation, I am not sure how to assign another (single variable) method as an input variable.
I thought of something like this:
public static int sum(int lowerbound, int upperbound, function(int x)){
int partialsum = 0;
for (int i = lowerbound; i <= upperbound; i++){
partialsum = partialsum + function(i);
}
return partialsum;
}
Is it possible?