我们不妨拿新出生的一对小兔子分析一下: 第一个月小兔子没有繁殖能力,所以还是一对; 两个月后,生下一对小兔总数共有两对; 三个月以后,老兔子又生下一对,因为小兔子还没有繁殖能力,所以一共是三对; …… 依次类推可以列出下表: 经过月数 0 1 2 3 4 5 6 7 8 9 10 11 12 幼仔对数 0 1 1 2 3 5 8 13 21 34 55 89 144 成兔对数 1 1 2 3 5 8 13 21 34 55 89 144 233 总体对数 1 2 3 5 8 13 21 34 55 89 144 233 377 import java.util.Scanner;
public class Prog10 {
public static void main(String[] args) { Scanner cin=new Scanner(System.in); int n=cin.nextInt(); int a=0,b=1,c=1;
if(n==1){System.out.println(a ); System.out.println(b ); System.out.println(c );} else
{
for(int i=2;i<=n;i++) { a=b; b=c; c=a+b; }
System.out.println(\幼崽数\成年兔子书\总数\ }
}
}
11.输出100~10000之间个位数为3的所有素数。
public class Prog11 {
36--6
public static void main(String[] args) { for(int i=103;i<10000;i=i+10) }
12. 百钱买百鸡问题:公鸡每只 5 元,母鸡每只 3 元,小鸡 3 只一元,问一百元买一百只鸡有几种买法.
public class Prog12 {
public static void main(String[] args) { }
13. 请编制程序要求输入整数a和b,若a2+b2大于100,则输出a2+b2百位以上的数字,否则输出两数之和。
import java.util.Scanner; public class Prog13 {
36--7
}
{
boolean flag=true;
for(int j=2;j
if(i%j==0)
{flag=false;break;}
}
if(flag==true){System.out.println(i);} }
int m=0;
for(int a=0;a<100;a++) {
for(int b=0;b<100;b++)
{
for(int c=0;c<100;c++)
if(5*a+3*b+1/3*c==100&&a+b+c==100) m++; }
}
System.out.print(\一百元买一百只鸡有\种买法\}
public static void main(String[] args) { System.out.print(\请输入两个整数\\n\ }
14. 编程实现:对键盘输入的任意一个四位正整数,计算各位数字平方和。 如:2345 ,则:计算22+32+42+52
import java.util.Scanner; public class Prog14 {
public static void main(String[] args) {
System.out.print(\请输入任意一个四位正整数\\n\ int sum=0;
Scanner cin=new Scanner(System.in);
int a=cin.nextInt();
sum=(a/1000*a/1000)+((a/100)*(a/100))+((a/100)*(a/100))+((a)*(a));
System.out.print(sum); }
15. 有1020个西瓜,第一天卖一半多两个,以后每天卖剩下的一半多两个,问几天以后能卖完,请编程.
public class Prog15 {
36--8
}
Scanner cin=new Scanner(System.in); int a=cin.nextInt();
int b=cin.nextInt(); if(a*a+b*b>100) {
System.out.print(a*a+b*b); } else
System.out.print(a+b);
}
public static void main(String[] args) { int m=0,sum=1020; do{
sum=sum/2-2; m++;
}while(sum>=0);
System.out.print(m+\天以后能卖完\
}
}
16. 编程,输出200以内所有完全平方数C(满足C2=A2+B2)及其个数.
public class Prog16 {
public static void main(String[] args) { int m=0; for(int C=1;C<200;C++) {
for(int A=1;A<=200;A++) { for(int B=1;B<=200;B++)
{
if(A*A+B*B==C*C)
{System.out.println(C); A=201; B=201; m++;}
}
}
}
System.out.println(\个数为:\
}
36--9
}
17. 设N是一个四位数,它的9倍恰好是其反序数(例如:123的反序数是321),编程,输出所有满足条件的N。
package easy;
public class The17 {
static long s,M; public static void main(String[] args) { for(long N=1009;N<=1109;N=N+10){ M=9*N; s=0;
while(M>0){
s=s*10+M; M=M/10; }
if(N==s)
System.out.println(s);
}
} }
18. 编程,输出555555的约数中最大的三位数。 package easy; public class The18th {
public static void main(String[] args) { double a=555555; long b=0;
//long[] yueShu=new long[555555]; for(long i=1;i<=555555;i++){
if(a%i==0&&i>99&&i<1000){
36--10