有两种砖,分别是1*1的砖和1*2的砖,用这两种砖铺1*N的地面,问共有多少种铺法。输入为N,请输出相应的铺法数
输入:
3
输出:
输入:
3
输出:
3
这道题我的理解可能不正确 -_-!
package javatest012;
import java.util.Scanner;
/*
* 有两种砖,分别是1*1的砖和1*2的砖,用这两种砖铺1*N的地面,问共有多少种铺法。输入为N,请输出相应的铺法数
输入:
3
输出:
3
*/
public class Brick {
final int birck0=1;
final int brick1=2;
public int times(int n)
{
if(n==0)
{
return 0;
}
if(n==1)
{
return 1;
}
if(n==2)
{
return 2;
}
return times(n-1)+times(n-2);
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("请输入N即铺 砖面积:");
int area;
Scanner in=new Scanner(System.in);
area=in.nextInt();
Brick brick=new Brick();
System.out.println(brick.times(area));
in.close();
}
}