20. To find the sum of the following series using recursion : 1^2 2^2 3^2 ..... n^2 - prabhatrocks07/Core-Java-Programming GitHub Wiki

public class SumOfSeries {

public static void main(String[] args) {
	System.out.println("Enter value of n: ");
	Scanner sc = new Scanner(System.in);
	int n = sc.nextInt();
	sc.close();
	
	System.out.println("Sum of series : " + sum(n));
}

private static int sum(int n) {
	if(n == 1) {
		return 1;
	} else {
		return (n*n) + sum(n -1);
	}
}
}