Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package fibonacci;
- import javax.swing.JOptionPane;
- /**
- *
- * @author Daniel 5
- */
- public class Fibonacci {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- int val;
- String valor;
- valor = JOptionPane.showInputDialog("Ingrese un valor: ");
- val = Integer.parseInt(valor);
- printFibonacciSequence(val);
- }
- private static void printFibonacciSequence(final int val) {
- int num1 = 0, num2 = 1, num3;
- for(int x = 0; x < val; x++) {
- num3 = num1 + num2;
- num1 = num2;
- num2 = num3;
- System.out.println(" "+ num1);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement