Recursive implementation of the Fiboacci number

2019-09-30

import  java.util.ArrayList;

import java.util.List;
import java.util.Scanner;

public class Demo01 {
public static void main(String[] args) {

/**
* 11~23, get the nth Fibonacci number
*/
List
list = new ArrayList();

Scanner sc
= new Scanner(System.in);

System.out.println(
"How many Fibonacci numbers do you want to get:");

int n = sc.nextInt();

for (int i = 0; i ) {

list.add(me(i));
}
System.out.println("the "+n+" Fibonacci number is: "+list.get(n-1) );

/**
* 28~31, get the first 10 Fibonacci numbers
*//*
for (int i=0;i<10;i++) {

System.out.println(me(i));
}
*/
}

static int me(int n) {

if (n <0) {
throw new IllegalArgumentException("x<0"< span style="color: #000000;">);
}
if (n == 0) {
return 0;
}
if (n == 1) {
return 1;
}
return me(n-1) + me(n-2) ;
}
}

import java.util.ArrayList;

import java.util.List;
import java.util.Scanner;

public class Demo01 {
public static void main(String[] args) {

/**
* 11~23, get the nth Fibonacci number
*/
List
list = new ArrayList();

Scanner sc
= new Scanner(System.in);

System.out.println(
"How many Fibonacci numbers do you want to get:");

int n = sc.nextInt();

for (int i = 0; i ) {

list.add(me(i));
}
System.out.println("the "+n+" Fibonacci number is: "+list.get(n-1) );

/**
* 28~31, get the first 10 Fibonacci numbers
*//*
for (int i=0;i<10;i++) {

System.out.println(me(i));
}
*/
}

static int me(int n) {

if (n <0) {
throw new IllegalArgumentException("x<0"< span style="color: #000000;">);
}
if (n == 0) {
return 0;
}
if (n == 1) {
return 1;
}
return me(n-1) + me(n-2) ;
}
}

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 5291 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.