NowCoder小时候走路喜欢蹦蹦跳跳,他最喜欢在楼梯上跳来跳去。
但年幼的他一次只能走上一阶或者一下子蹦上两阶。
现在一共有N阶台阶,请你计算一下NowCoder从第0阶到第N阶共有几种走法。
输入描述:
输入包括多组数据。每组数据包括一个整数n, (1≤n≤90)。
输出描述:
对应每个输入包括一个输出。 为redraiment到达第n阶不同走法的数量。
示例1
输入
1 2
输出
1 2
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main{
public static void main(String[] args) throws IOException{
BufferedReader sc = new BufferedReader(new InputStreamReader(System.in));
long[] a = new long[100];
a[0] = 1;
a[1] = 2;
for(int i = 2 ; i < 100;i++) {
a[i] = a[i - 1] + a[i - 2];
}
String b = null;
while((b = sc.readLine()) != null) {
int c = Integer.valueOf(b);
System.out.println(a[c - 1]);
}
sc.close();
}
}
练习一下InputStreamReader的语法,多组读入,抛异常