package a; public class Tuzi { public static void main(String[] args) { int a=1,b=0,c=0,sum = 0;//a 幼兔对数,b 小兔对数,c 成兔对数,sum 总对数 for (int i = 1; i <=24; i++) { if (i == 1) { a = 1; b = 0; c = 0; } else { c = b + c; b = a; a = c; } sum = a + b + c; System.out.println(i+"个月后,一共有兔子" + sum + "对,其中幼兔" + a + "对,小兔" + b + "对,成兔" + c + "对!"); } }
时间: 2024-10-20 04:48:47