Programmin-in-Python

Printing Fibonacci series

Jan 30th, 2021
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.44 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. class sample{
  4.     public static void main(String[] args) {
  5.         int f=0, s=1, t, temp;
  6.  
  7.         Scanner scan_end = new Scanner(System.in);
  8.         System.out.print("Enter the number of terms : ");
  9.         String str_end = scan_end.nextLine();
  10.         int end = Integer.parseInt(str_end);
  11.  
  12.         System.out.println(f);
  13.         System.out.println(s);
  14.  
  15.         for (int i=0;i<end-2;i++){
  16.             t = f + s;
  17.             System.out.println(t);
  18.             f = s;
  19.             s = t;
  20.         }
  21.     }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment