Skip to content

Instantly share code, notes, and snippets.

@pedronaves
Created April 29, 2014 22:57
Show Gist options
  • Select an option

  • Save pedronaves/bbd3caee228c1dcf20b1 to your computer and use it in GitHub Desktop.

Select an option

Save pedronaves/bbd3caee228c1dcf20b1 to your computer and use it in GitHub Desktop.
package fibonacci;
import javax.swing.JOptionPane;
public class Fibonacci {
public static void main(String[] args) {
int n = Integer.parseInt(JOptionPane.showInputDialog("Digite um valor"));
for (int i = 0; i < 11; i++) {
if(i == 10) {
System.out.print("(" + i + "):" + Sequencia.fibo(i) + "\t");
}
}
}
}
package fibonacci;
public class Sequencia {
static int fibo(int n) {
if (n < 2) {
return n;
} else {
return fibo(n - 1) + fibo(n - 2);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment