Advertisement
chiplu

Java fibonacci sequence

Nov 17th, 2019
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.48 KB | None | 0 0
  1. package dadaproject.company;
  2. import java.util.Scanner;
  3. public class Main {
  4.  
  5.     public static void main(String[] args) {
  6.  
  7.  
  8.         int i1 = 0, i2 = 1, sum, num;
  9.         System.out.println("Enter the number of terms:");
  10.         Scanner number = new Scanner(System.in);
  11.         num = number.nextInt();
  12.         for (int i = 1; i <= num; i++) {
  13.             sum = i1 + i2;
  14.             System.out.print(i1+" ");
  15.             i1 = i2;
  16.             i2 = sum;
  17.         }
  18.  
  19.  
  20.     }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement