Last active
April 29, 2016 18:14
-
-
Save paulopatto/09d1f291d631b5414440872209a5eab7 to your computer and use it in GitHub Desktop.
Como escrever código
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 int getFibonacciNumber(int n) { | |
switch(n) { | |
case 1: return 1; | |
case 2: return 1; | |
case 3: return 2; | |
case 4: return 3; | |
case 5: return 5; | |
case 6: return 8; | |
case 7: return 13; | |
default: return -1; // good enough for the demo | |
} | |
} |
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 int fibonacci(int n) { | |
if (n == 1) { | |
return 1; | |
} | |
else if (n == 2) { | |
return 2; | |
} | |
else { | |
return fibonacci(n-2) + fibonacci(n-2); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment