joseleonweb

Untitled

Aug 12th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.59 KB | None | 0 0
  1. class ImprovedFibonacci {
  2.    
  3.     static final int MAX_INDEX = 9;
  4.    
  5.     /**
  6.     * Print out the first few Fibonacci numbers,
  7.     * marking evens with a '*'
  8.     */
  9.     public static void main(String[] args) {
  10.         int lo = 1;
  11.         int hi = 1;
  12.         String mark;
  13.  
  14.        System.out.println("1: " + lo);
  15.        for (int i = 2; i <= MAX_INDEX; i++) {
  16.            if (hi % 2 == 0)
  17.                mark = " *";
  18.            else
  19.                mark = "";
  20.            System.out.println(i + ": " + hi + mark);
  21.            hi = lo + hi;      
  22.            lo = hi - lo;
  23.        }
  24.     }
  25. }
Add Comment
Please, Sign In to add comment