Advertisement
Guest User

Fibonacci_Daniel

a guest
Jul 10th, 2014
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.97 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6.  
  7. package fibonacci;
  8.  
  9. import javax.swing.JOptionPane;
  10.  
  11. /**
  12.  *
  13.  * @author Daniel 5
  14.  */
  15. public class Fibonacci {
  16.  
  17.     /**
  18.      * @param args the command line arguments
  19.      */
  20.     public static void main(String[] args) {
  21.        int val;
  22.        
  23.        String valor;
  24.        
  25.        valor = JOptionPane.showInputDialog("Ingrese un valor: ");
  26.        
  27.        val = Integer.parseInt(valor);
  28.        
  29.        printFibonacciSequence(val);
  30.     }
  31.    
  32.     private static void printFibonacciSequence(final int val) {
  33.         int num1 = 0, num2 = 1, num3;
  34.        
  35.         for(int x = 0; x < val; x++) {
  36.            num3 = num1 + num2;
  37.            
  38.            num1 = num2;
  39.            
  40.            num2 = num3;
  41.            
  42.            System.out.println(" "+ num1);
  43.        }
  44.     }
  45.    
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement