Guest User

Untitled

a guest
Jul 16th, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.55 KB | None | 0 0
  1. public class PrimitiveRecursive {
  2.    
  3.     public static void main(String[] args) {
  4.         int x, y = -1;
  5.         try {
  6.             x = Integer.parseInt(args[0]);
  7.             y = Integer.parseInt(args[1]);
  8.         } catch (Exception e) {
  9.             System.out.println("Please enter valid numbers.");
  10.             return;
  11.         }
  12.         int result = compute(x, y);
  13.         System.out.println("FINALLY: " + result);
  14.        
  15.     }
  16.  
  17.     private static int compute(int x, int y) {
  18.         if (x == 0) {
  19.             return y+1;
  20.         }
  21.         if (y == 0) {
  22.             return compute(x-1, 1);
  23.         }
  24.         else {
  25.             return compute(x-1, compute(x, y-1));
  26.         }
  27.    
  28.     }
  29.  
  30. }
Add Comment
Please, Sign In to add comment