diloentutospc

Serie fibonacci

Oct 2nd, 2018
12,820
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.40 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class SerieFibonacci {
  4.  
  5.     public static void main(String[] args) {
  6.        
  7.         Scanner teclado = new Scanner(System.in);
  8.        
  9.         int a = 0, b = 1, c, n;
  10.        
  11.         System.out.print("Por favor ingrese cantidad de elmentos para la serie: ");
  12.         n = teclado.nextInt();
  13.        
  14.         for (int i = 0; i < n; i++) {
  15.             System.out.println(a);
  16.             c = a + b;
  17.             a = b;
  18.             b = c;
  19.         }
  20.     }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment