I have just been studying the concept of recursion and I thought that I would try a simple example. In the following code, I am attempting to take the numbers: 1, 2, 3, 4, 5, an
It could also be written like this:
public static int sum(int n){ int total; if(n==1){ total =1; }else{ total = sum(n-1)+n; } return total; }