Fibonacci Word - Java Algorithm

Java examples for Algorithm:String

Description

Fibonacci Word

Demo Code



public class FibonacciWord {
    public static void main(String args[]) {
        FibonacciWord fb = new FibonacciWord();
        System.out.println(fb.fibo(3));
    }//  w  w  w.  j a va 2  s  . c om

    public String fibo(int n) {
        if (n == 2) {
            return "ba";
        } else if (n == 1) {
            return "b";
        } else if (n == 0) {
            return "a";

        } else {
            return fibo(n - 1) + "" + fibo(n - 2);
        }
    }
}

Related Tutorials