高中数学?_JAVA
生活随笔
收集整理的這篇文章主要介紹了
高中数学?_JAVA
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Description
高中數學大家都學過數列,其中一個重要的概念就是數列的通項,可以代表數列中每一項的一個表達式。
今天我們的問題就跟通項有關系,說,給你一個數列的通項和數列中的前幾項,希望你能求出它的第n項。
通項表達式如下:
F(1) = 0;
F(2) = 1;
F(n) = 4F(n-1)-5F(n-2);
Input
輸入數據第一行是一個正整數T,T<100。接下來T行,每行一個整數n, 2<n<50。
Output
輸出有T行,對于輸入中每行中的n按照通項計算出F(n)。
Sample
Input
4
3
4
5
6
Output
4
11
24
41
import java.util.*;class F {int n;public F(int n) {this.n = n;}public void sum() {int a[] = new int[55];a[1] = 0;a[2] = 1;for (int i = 3; i <= n; i++)a[i] = 4 * a[i - 1] - 5 * a[i - 2];System.out.println(a[n]);} }public class Main {public static void main(String[] args) {Scanner reader = new Scanner(System.in);int t = reader.nextInt();while(t-- > 0) {F f = new F(reader.nextInt());f.sum();}reader.close();}}總結
以上是生活随笔為你收集整理的高中数学?_JAVA的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: bLue的二叉树_JAVA
- 下一篇: 数字_JAVA