Mahmoud_Hawara

Untitled

Jan 7th, 2026
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.36 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class Main {
  4.    
  5.     public static int square(int n) {
  6.         if (n == 1) return 1;
  7.         return square(n - 1) + 2 * n - 1;
  8.     }
  9.    
  10.     public static int cube(int n) {
  11.         if (n == 1) return 1;
  12.         return cube(n - 1) + 3 * square(n) - 3 * n + 1;
  13.     }
  14.    
  15.     public static void main(String[] args) {
  16.         System.out.println(cube(5));
  17.     }
  18. }
Advertisement
Add Comment
Please, Sign In to add comment