I need to use recursion to make an algorithm which finds the sum of x integers after an integer m. For example, if m is 2 and n is 5, I would need to find the sum of 2+3+4+5+6 using recursion.
The code I have so far would (for the example illustrated above) works in such way: 2+3+3+3+3. Any help at all is greatly appreciated as I have an exam tomorrow and questions like these may be included.
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Input a value for n");
int n = input.nextInt();
System.out.println("Input a value for m");
int m = input.nextInt();
System.out.println(sho (m,n));
}
public static int sho (int m, int n){
int sum = 0;
if(n<=0){
return m;
}
sum = sho(m+1,n-1);
sum = sum +(m);
return sum;
}