trying to pass default params to tail recursion function
In this code:
Code :
public static void main(String[] args) {
System.out.println(tailrecsum(5,0));
}
private static int tailrecsum(int x,int running_total, int default_total){
if(x == 0){
return running_total;
}
else {
return tailrecsum(x-1, running_total+x);
}
}
I get an error "The method tailrecsum(int, int, int) in the type MainClass is not applicable for the arguments (int, int)"
on this line:
Code :
return tailrecsum(x-1, running_total+x);
I know java doesn't support default parameters, so I use overloading, but not sure why I get the error.
Re: trying to pass default params to tail recursion function
you define 3 parameters in tailrecsum(int, int, int) but invoke with 2 parameters in return tailrecsum(int, int)