Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class PrimitiveRecursive {
- public static void main(String[] args) {
- int x, y = -1;
- try {
- x = Integer.parseInt(args[0]);
- y = Integer.parseInt(args[1]);
- } catch (Exception e) {
- System.out.println("Please enter valid numbers.");
- return;
- }
- int result = compute(x, y);
- System.out.println("FINALLY: " + result);
- }
- private static int compute(int x, int y) {
- if (x == 0) {
- return y+1;
- }
- if (y == 0) {
- return compute(x-1, 1);
- }
- else {
- return compute(x-1, compute(x, y-1));
- }
- }
- }
Add Comment
Please, Sign In to add comment