JAVA basic programming exercises-1

Classical question: There is a pair of rabbits. From the third month after birth, a pair of rabbits will be born every month, and the little rabbit will give birth to a
pair of rabbits every month after the third month . If the rabbits are not dead, ask each What is the total number of rabbits in the month?

public class example1 {
	public static void main(String[] args) {
		Vector<Integer> v=new Vector<Integer>();
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		v.add(1);
		System.out.println(1);;
		v.add(1);
		System.out.println(1);
		for(int i=2;i<n;i++) {
			v.add(i,v.get(i-2)+v.get(i-1));
			System.out.println(v.get(i));
		}
	}
}

Guess you like

Origin blog.csdn.net/Warmmm/article/details/107545005