Focus mode

Backend Bootcamp Hazırlık Programı 4.Hafta

Pratik - Recursive ile Fibonacci Serisi Bulan Program

Recursive ile Fibonacci Serisi

Java'da recursive metotlar ile fibonacci serisi bulan program yapıyoruz.

public class JavaPatika {

    static int fibo(int n) {
        if (n == 1 || n == 2) {
            return 1;
        }
        return fibo(n - 1) + fibo(n - 2);
    }

    public static void main(String[] args) {
        // 1 1 2 3 5 8 13 21
        // f(n) = f(n-1) + f(n-2)
        // f(6) = f(5) + f(4)
        // f(5) = f(4) + f(3)
        // f(4) = f(3) + f(2)
        // f(3) = f(2) + f(1)

        System.out.println(fibo(7));
    }
}
left-disk

Programs to Accelerate Your Progress in a Software Career

Join our 4-8 month intensive Patika+ bootcamps, start with the fundamentals and gain comprehensive knowledge to kickstart your software career!

right-cube

Comments

You need to enroll in the course to be able to comment!