Program to print fibonacci number in java.

import java.util.Scanner;
public class FibonacciExample {
    public static int f2(int n){
        if(n == 1 || n == 2){
            return 1;
        }
        return f2(n-1) + f2(n -2);
    }
    public static int f1(int n){
        if(n == 1 || n == 2){
            return 1;
        }
        int n1=1, n2=1, fb=1;
        for(int i= 3; i<= n; i++){
            fb = n1 + n2;
            n1 = n2;
            n2 = fb;
        }
        return fb;
    }
    public  static void main(String args[]){
        System.out.println("till how many number do you want to print FebinocaiSeries ");
        Scanner in = new Scanner(System.in);
        int n=in.nextInt();
        System.out.println("fb series upto " + n +" ns : ");
        for(int i=1; i<=n; i++){
            System.out.print(f2(i) +" ");
        }
    }

}