Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class PrimitiveRecursive {
- public static void main(String[] args) {
- int x = -1, y = -1;
- try {
- x = Integer.parseInt(args[0]);
- y = Integer.parseInt(args[1]);
- } catch (Exception e) {
- System.out.println("Please enter valid numbers. I'll give you another chance.");
- }
- if (x < 0 && y < 0) {
- Scanner scan = new Scanner(System.in);
- System.out.println("Please enter X:");
- try {
- x = Integer.parseInt(scan.nextLine());
- } catch (Exception e) {
- System.out.println("you suck!");
- return;
- }
- System.out.println("Please enter Y:");
- try {
- y = Integer.parseInt(scan.nextLine());
- } catch (Exception e) {
- System.out.println("you suck!");
- return;
- }
- }
- System.out.println("Hang on... computing");
- int result = compute(x, y);
- System.out.println("FINALLY: " + result);
- }
- private static int compute(int x, int y) {
- // System.out.println("X: " + x + ", Y: " + 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