입력된 n부터m 까지의 합을 구하시오
1 4 답 1+2+3+4 =10
package _2;
import java.util.*;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
System.out.print(sum(n,m));
}
public static int sum(int n ,int m) {
if(n==m) return m;
else
return n+sum(n+1,m);
}
}