Results 1 to 2 of 2
  1. #1
    rinopjoseph06 is offline Member
    Join Date
    Mar 2012
    Posts
    7
    Rep Power
    0

    Unhappy TRIED THis CODE for TO FIND THE FIBONACCI USING THREAD ,BUT SHOWING ERROR FOR FOLLOWI

    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;
    }
    }

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: TRIED THis CODE for TO FIND THE FIBONACCI USING THREAD ,BUT SHOWING ERROR FOR FOL

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Replies: 9
    Last Post: 05-28-2013, 09:14 AM
  2. Replies: 6
    Last Post: 05-26-2013, 02:53 AM
  3. Multiple Thread Fibonacci Code
    By pooshi in forum New To Java
    Replies: 5
    Last Post: 10-09-2012, 03:30 AM
  4. Replies: 3
    Last Post: 09-20-2012, 11:11 AM
  5. Find the Error in Class Code
    By Humphrey Bogart in forum New To Java
    Replies: 3
    Last Post: 03-30-2011, 04:43 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •