童年生活二三事(語法)
阿新 • • 發佈:2018-12-24
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的語法,多組讀入,拋異常