-
-
Save parzibyte/1087829b8222a3b7fb58b265bf8aae7d 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
/** | |
* Sucesión fibonacci iterativo en Java | |
* | |
* @author parzibyte | |
*/ | |
public static long fibonacci(long posicion) { | |
long siguiente = 1, actual = 0, temporal = 0; | |
for (long x = 1; x <= posicion; x++) { | |
// Si no quieres imprimirla, comenta la siguiente línea: | |
System.out.print(actual + ", "); | |
temporal = actual; | |
actual = siguiente; | |
siguiente = siguiente + temporal; | |
} | |
// Si no quieres imprimirla, comenta la siguiente línea: | |
System.out.println(actual); | |
return actual; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment