Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Fibonacci {
- /** Print out the Fibonacci sequence for values < 50 */
- public static void main(String[] args) {
- int lo = 1,
- hi = 1;
- System.out.println("Fibonacci sequence until 50");
- System.out.println("---------------------------");
- System.out.println(lo);
- while (hi < 50) {
- System.out.println(hi);
- hi = lo + hi; // new hi
- lo = hi - lo; /* new lo is (sum - old lo)
- that is, the old hi */
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement