Analysis:
There are a total of 25 steps, each step has two kinds of steps, go first level, or go two level. In two cases: if the first time to walk two, then there are
25-2=23 Ladder to go. And then ask for the remaining 23 steps to the total number of walking method. If the first step, then there are 25-1 = 24 steps
To go, so the total number of steps after the 25 ladder, is equal to climb the 23 steps Total method + climb up the 24 steps of the total number of methods. And the 23 pole can
Then divided into (23-1), (23-2) level ladder. By analogy, this is a typical recursive type. We can easily figure out when
There are 1 and 2 steps when all the Times: 1 and 2 respectively. The function of the total number of methods is calculated as follows:
---------------------------------Getnum ()---------------------------------------------
public int getnum (int i)
{
int r=0;
if (i>2)
{
Num=getnum (i-1) +getnum (i-2);
return num;
}
else if (i==1)
{
R=1;
}
else if (i==2)
{
r=2;
}
return R;
}
---------------------------------------------------------------------------------------
The test program is written in Java. Run using command: Java stair 25