Skip to content

Instantly share code, notes, and snippets.

@thejavalistener
Created March 27, 2014 17:02
Show Gist options
  • Save thejavalistener/9812587 to your computer and use it in GitHub Desktop.
Save thejavalistener/9812587 to your computer and use it in GitHub Desktop.
package com.thejavalistener.post.simple;
import java.util.Scanner;
public class Fibonacci
{
public static void main(String[] args)
{
// scanner me permite leer datos por consola
Scanner scanner = new Scanner(System.in);
// el usuario ingresa un valor numerico
System.out.print("Ingrese un valor numerico: ");
int n = scanner.nextInt();
double fib = fibonacci(n);
System.out.println("El termino "+n+" de Fibonacci es: "+fib);
}
private static double fibonacci(int n)
{
if( n<=2 )
{
return 1;
}
else
{
return fibonacci(n-1)+fibonacci(n-2);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment