JAVA Program using Threads to Print Fibonacci Series and Cube of Numbers

JAVA Program using Threads to Print Fibonacci Series and Cube of Numbers:


class cub extends Thread
{
 public void run()
 {
    System.out.println("First series:");
   int j;
   for(int i=1;i<=20;i++)
   {
    j=i*i*i;
    System.out.print("\t"+j);
   }
   System.out.println();
  }
}

class fibo extends Thread
{
  public void run()
  {
      System.out.println("Second series:");
   long fno=1,sno=1,fibo=0;
   System.out.print("\t"+fno);
   System.out.print("\t"+sno);

   for(int i=1;i<=20;i++)
   {
    fibo=fno+sno;
    System.out.print("\t"+fibo);
    fno=sno;
    sno=fibo;
   }
  }
}

class thread5
{
  public static void main(String args[])
  {
   cub c= new cub();
   c.setPriority(Thread.MAX_PRIORITY);
   c.start();

   fibo f=new fibo();
   f.setPriority(Thread.MIN_PRIORITY);
   f.start();
  }
}

OUTPUT:

First series:
        1       8       27      64      125     216     343     512     729     1000    1331    1728    2197    2744
3375    4096    4913    5832    6859    8000

Second series:
        1       1       2       3       5       8       13      21      34      55      89      144     233     377
610     987     1597    2584    4181    6765    10946   17711



Leave a Reply

Your email address will not be published. Required fields are marked *

seven + 13 =