Advertisement
joseleonweb

Untitled

Sep 17th, 2019
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.55 KB | None | 0 0
  1. class Fibonacci {
  2.     /** Print out the Fibonacci sequence for values < 50 */
  3.     public static void main(String[] args) {
  4.         int lo = 1,
  5.             hi = 1;
  6.        System.out.println("Fibonacci sequence until 50");
  7.        System.out.println("---------------------------");
  8.  
  9.        System.out.println(lo);
  10.        while (hi < 50) {
  11.            System.out.println(hi);
  12.            hi = lo + hi;       // new hi
  13.            lo = hi - lo;       /* new lo is (sum - old lo)
  14.                                   that is, the old hi */
  15.        }
  16.     }
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement