Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class SumOfSquare {
- private static int sumOfSquare(int n, int acc) {
- if (n == 0) return acc;
- return sumOfSquare(n - 1, acc + n * n);
- }
- private static int sumOfSquare(int n) {
- return n * (n + 1) * (2 * n + 1) / 6;
- }
- public static void main(String[] args) {
- System.out.println("sum = " + sumOfSquare(50, 0));
- System.out.println("sum = " + sumOfSquare(50));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement