Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class Main {
- public static int square(int n) {
- if (n == 1) return 1;
- return square(n - 1) + 2 * n - 1;
- }
- public static int cube(int n) {
- if (n == 1) return 1;
- return cube(n - 1) + 3 * square(n) - 3 * n + 1;
- }
- public static void main(String[] args) {
- System.out.println(cube(5));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment