/* * Copyright (c) 2001 Matthew Feldt. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided the copyright notice above is * retained. * * THIS SOFTWARE IS PROVIDED ''AS IS'' AND WITHOUT ANY EXPRESSED OR * IMPLIED WARRANTIES. */ /** * CountThreeTerms.java * * Java Examples In A Nutshell Copyright (c) 2000 David Flanagan * Exercise 1-2: * Each term of the Fibonacci series is formed by adding the previous two * terms. What sort of series do you get if you add the previous three terms? * Write a program to print the first 20 terms of this series. * * @author Matthew Feldt * @version 1.0 */ package com.feldt.examples.basics; import java.lang.*; class CountThreeTerms { public static void main(String[] args) { final int CEILING = 20; int i1 = 1, i2 = 1, i3 = 2, i4; System.out.println(i1); System.out.println(i2); System.out.println(i3); for (int i = 3; i < CEILING; i++) { i4 = i1 + i2 + i3; System.out.println(i4); i1 = i2; i2 = i3; i3 = i4; } } }