有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第三个月后每个月又生一对兔子,假如兔子都不死,问每个月的兔子总数为多少?
package chao; import java.util.Scanner; public class tu { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("请输入月份:"); int b=1; int c=1; int s=1; int temp; int a = sc.nextInt(); if( a==1 || a==2) { System.out.println("兔子的数量为1对"); }else { for(int i = 3;i<=a;i++) { s=b+c; c=b; b=s; } } System.out.println("兔子的数量为"+s+"对"); } }
用*打印 直角三角形
package chao; import java.util.Scanner; public class zhijiao { public static void main(String[] args) { for(int i = 1; i<=5;i++) { for(int a= 1;a<=1+(i-1)*2;a++) { System.out.print("*"); } System.out.println(""); } } }
标签:Scanner,int,System,兔子,chao,第二周,第四天,五日,public From: https://www.cnblogs.com/youxiandechilun/p/17537715.html