JAVA CODE

//Ex8_9 program
import java.applet.Applet;
import java.awt.*;

public class Ex8_9 extends Applet
{
   public void paint (Graphics g)
   {
      g.drawString ("The first 20 Fibonacci numbers are:", 20, 20);

      for (int i = 2; i <= 21; i++)
         g.drawString (fibonacci(i) + "", 20 + 35 * ((i - 2) % 10),
            40 + 20 * (i / 12));
   }

   private int fibonacci (int n)
   {
      int f1 = 0, f2 = 1, fib = 0;

      if (n < 2)
         return f1;
      else if (n < 3)
         return f2;
      else
      {
         for (int i=2; i