Recursion/Recursive Methods Part 1

PHOTO EMBED

Tue Apr 20 2021 01:29:37 GMT+0000 (Coordinated Universal Time)

Saved by @ahmedqgqgq #java

public class MyName {
    static void fun() {
        System.out.println("Hi");
        fun();
    }
    public static void main(String[] args) {
        fun();
    }
}
public class MyName {
    static int count = 0;
    static void fun() {
        count++;
        if (count < 5) {
            System.out.println("Hi");
            fun();
        }
    }
    public static void main(String[] args) {
        fun();
    }
}
public class MyName {
    static int count = 0;
    static void fun() {
        count++;
        if (count < 5) {
            System.out.println("Hi");
            fun();
        }
    }
    public static void main(String[] args) {
        fun();
    }
}
public class MyName {
    static int count = 0;
    static void fun() {
        count++;
        if (count < 5) {
            System.out.println("Hi");
            fun();
        }
        count++;//error.
    }
    public static void main(String[] args) {
        fun();
    }
}
public class MyName {
    static int count = 0;
    static void fun() {
        if (count == 5) {// base case
            return;
        }
        count++;
        System.out.println("Hi Ahmed");
        fun();
    }
    public static void main(String[] args) {
        fun();
    }
}
public class MyName {
    static int count = 0;
    static void fun() {
        if (count == 5) {// base case
            return;
        }
        count++;
        System.out.println("Hi Ahmed");
        fun();
    }
    public static void main(String[] args) {
        fun();
    }
}
public class MyName {
    static int fact(int n) {// 5!=5*4*3*2*1
        if (n == 1) {
            return n;
        } else {
            return n * fact(n - 1);
        }
    }
    public static void main(String[] args) {
        System.out.println("fact==" + fact(5));
    }
}
public class MyName {
    static int fact(int n) {// 5!=5*4*3*2*1
        if (n == 1||n==0) {
            return n;
        } else {
            return n * fact(n - 1);
        }
        /*5*fact(4)
        4*fact(3)
        3*fact(2)
        2*fact(1)
        1 
        */
    }
    public static void main(String[] args) {
        System.out.println("fact==" + fact(5));
    }
}
public class MyName {
    static void fun(int n) {
        if (n < 1) {
            return;
        } else {
            System.out.println("# " + n);
            fun(n - 1);
        }
    }
    public static void main(String[] args) {
        fun(5);
    }
}
public class MyName {
    static void fun(int n) {
        if (n < 1) {
            return;
        } else {
            fun(n - 1);
            System.out.println("# " + n);
        }
    }
    public static void main(String[] args) {
        fun(5);
    }
}
public class MyName {
    static int fact(int n) {
        if (n == 1) {//no n==75
            return 1;
        } else {
            return n * fact(n - 1);
        }
    }
    public static void main(String[] args) {
        System.out.println("fact =" + fact(10));//no fact =75
    }
}
public class MyName {
    static void directRecfun(){
        directRecfun();
    }
    static void indirectRecfun1(){
        indirectRecfun2();
    }
    static void indirectRecfun2(){
        indirectRecfun1();
    }
    public static void main(String[] args) {
        
    }
}


content_copyCOPY