View Code of Problem 23

import java.util.Scanner;

class Rabbit {
	long fun(int n) {
		if(n==1) {
			return 1;
		}else if(n==2) {
			return 2;
		}else {
			long a[] = new long [100];
			a[0]=1;a[1]=2;
			int i;
			for(i=2;i<n;i++) {
				a[i]=a[i-1]+a[i-2];
			}
			return a[i-1];
		}
	}
}

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scan =new Scanner(System.in);
		int n = scan.nextInt();
		Rabbit rabbit = new Rabbit();
		while(n!=0) {
			System.out.println(rabbit.fun(n));
			n=scan.nextInt();
		}
		
	}

}

Double click to view unformatted code.


Back to problem 23