Created
August 11, 2012 20:33
-
-
Save brunoperezm/3327064 to your computer and use it in GitHub Desktop.
Diferent ways of calculating the fibonacci sequence
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
public class funciones { | |
public static void main (String args[]) { | |
long start = System.currentTimeMillis(); | |
fibonacci(); | |
long elapsedTimeMillis = System.currentTimeMillis()-start; | |
float elapsedTimeSec = elapsedTimeMillis/1000F; | |
System.out.println(elapsedTimeSec); | |
} | |
public static void fibonacci (long maximo) { | |
long numeroActual = 2; | |
long numeroAnterior = 1; | |
long numeroFuturo = 0; | |
for (long x=2;x<maximo;x++) { | |
if (x != 2) | |
numeroAnterior = numeroActual; | |
numeroActual = numeroFuturo; | |
numeroFuturo = numeroActual + numeroAnterior; | |
//System.out.println(numeroFuturo); | |
} | |
} | |
public static void fibonacci () { | |
// MANU | |
long x = 0; | |
long y = 1; | |
for (long a=1;a<100000000;a++){ | |
if (a%2==0){ | |
x=x+y; | |
//System.out.println(x); | |
}else{ | |
y=x+y; | |
//System.out.println(y); | |
} | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment