Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.JOptionPane;
- public class Fibonacci {
- public static void main(String[] args) {
- int off = 0, soma = 0, somaAnt = 0;
- String seq = "";
- String limite = JOptionPane.showInputDialog("Insira o limite");
- int limiteInt = Integer.parseInt(limite);
- for(int i=1; i<limiteInt; i++) {
- if(i == 1) {
- somaAnt = 0;
- seq += somaAnt + ", ";
- continue;
- }
- if(i == 2) {
- soma = 1;
- seq += soma + ", ";
- continue;
- }
- off = soma + somaAnt;
- somaAnt = soma;
- soma = off;
- seq += off + ", ";
- }
- JOptionPane.showMessageDialog(null, seq);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement