Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Name: Fibonacci numbers-function method (bottom-up)
- * @author LinChuWen
- * Date: 2014.10.14
- *
- * NCHU EE,course number:2335
- * course name: Object Oriented Language
- * Textbook: Big Java:Late Objects-Cay S. Horstmann
- * Problem: P4.16
- * Description: Enter an integer "n", then prints the nth Fibonacci number.
- */
- import java.util.*;
- public class HW3_P4_16_function {
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- while(input.hasNext()){
- int n = input.nextInt();
- System.out.println(fibonacci(n));
- } //while end
- input.close();
- } //main end
- static long fibonacci( long number ){
- long[] Fib = new long[1000];
- Fib[0]=0;Fib[1]=Fib[2]=1;
- for(int cnt=2;cnt<=number;cnt++){
- Fib[cnt]=Fib[cnt-1]+Fib[cnt-2];
- } //for end
- return Fib[(int) number];
- } //fibonacci() end
- } //class end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement