3 Replies Latest reply: Jun 27, 2013 5:23 PM by rp0428 RSS

    TRIED THis CODE for TO FIND THE FIBONACCI USING THREAD ,BUT SHOWING ERROR FOR FOLLOWING CODE  fib = fib(k+1);

    rinojoseph

      showing following error in line 34

       

       

      error: cannot find symbol

       

      fib = fib(k+1);

             ^

        symbol:   method fib(int)

        location: class FibN

      1 error

       

       

       

      import java.util.*;

      class AsynchFunctionTest

      {

      public static void main(String[]args)

      {

      Scanner in = new Scanner(System.in);

      System.out.print("enter value for n");

      int n = in.nextInt();

      FibN t = new FibN(n);

      t.start();

      try

      {

        t.join();

      }

      catch(InterruptedException e){}

      System.out.println("Fib("+n+") = "+ t.getResult());

      }

      }

       

       

       

       

       

      class FibN extends Thread

      {

      private int n;

        private long result;

      public FibN(int nn)

      {

        n = nn;

      }

        public void run()

      {

      long fib = 1;

      int k = 0;

      while(k < n){

      fib = fib(k+1);

      k++;

      }

      result = fib;

      }

      public long getResult()

      {

      return result;

      }

      }