<pre name="code" class="java">
N块石头,青蛙在第1块石头上。青蛙跳,每次只能跳1个或者2个。问跳到第N块石头一共有多少种不同的跳法
public class FrogJump {
public static int frogJumpWays(int n){
if(n == 1 || n ==2){
return 1;
}
int tmp = 1;
int num1 = 1;
int num2 = 1;
for(int i = 2; i < n; i++){
tmp = num2;
num2 += num1;
num1 = tmp;
}
return num2;
}
public static void main(String[] args){
System.out.println(frogJumpWays(4));
System.out.println(frogJumpWays(6));
System.out.println(frogJumpWays(40));
}
}