Advertisement
Guest User

Fibonacci Program...

a guest
Jul 20th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.01 KB | None | 0 0
  1. /*
  2.  
  3.     Name: Sean Myko C. Baang
  4.     Section: CC11 - CCB
  5.     Date: 07/18/2018
  6.  
  7. */
  8.  
  9. /* 
  10.  
  11.     Description: Fibonacci Series...
  12.  
  13. */
  14.  
  15. import java.util.Scanner;
  16.  
  17. class FibonacciProgram
  18. {
  19.    
  20.     public static void main(String args[])
  21.     {
  22.        
  23.         Scanner reader = new Scanner(System.in);
  24.        
  25.         System.out.println("[FIBONACCI SERIES by Sean Baang]"); // Credits... hekhek...
  26.        
  27.         System.out.println(" ");
  28.         System.out.println("[INPUT]: "); // char2 rani :)
  29.         System.out.println(" ");
  30.        
  31.         int ctr = reader.nextInt(); // userinput....
  32.        
  33.         System.out.println(" ");
  34.         System.out.println("[OUTPUT]"); // char2 rani :)
  35.         System.out.println(" ");
  36.            
  37.         int x = 0;
  38.         int y = 1;
  39.         int z;
  40.         int i;
  41.        
  42.         System.out.println(" " + x); // prints 0 because the fibonacci series starts with 0...
  43.         System.out.println(" " + y); // prints 1...
  44.        
  45.         for(i = 2; i < ctr; ++i) // Loops starts here..
  46.         {
  47.             z = x + y;
  48.        
  49.             System.out.println(" " + z ); // print the fibonacci series...
  50.            
  51.             x = y;
  52.             y = z;
  53.            
  54.         }
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement