Created
March 27, 2014 17:02
-
-
Save thejavalistener/9812587 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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