**Dynamic Multi-threading**. The program works just fine however, I'm not sure whether I am doing it dynamically, in other words, I would not like to recalculate fib(n-1) and fib(n-2) if it has been done already thus minimizing calculations in each step.

*. I used a static Array as an instance/global variable thinking that it will help me do this dynamically.*

**Would greatly appreciate your help on this**Following is the code that I did in JGrasp IDE

/*====================================================================================================================== Author: NIAZ MOHAMMAD This program finds the nth Fibonacci number using dynamic multi-threading (implying divide and conquere strategy)and recursion. ========================================================================================================================*/ import java.util.Scanner; public class Fibonacci implements Runnable { static long[] fib; public static void main(String[] args) { System.out.println("Enter an integer:(n>0) "); Scanner kbd = new Scanner(System.in); int n = kbd.nextInt(); if(n < 0) System.out.println("The " + n + "th Fibonacci number is: "+ 0);//in this program n<0, not defined so print 0 else if(n==0) System.out.println("The " + n + "th Fibonacci number is: "+ 0);//0th fibonacci number 0 else if(n==1) System.out.println("The " + n + "st Fibonacci number is: "+ 1);//1st Fibonacci number 1 else { long[] answers = new Fibonacci(n).getFib(); //exception 11th,12th,13th if(n==11||n==12||n==13)System.out.println("The " + n + "th Fibonacci number is: "+ answers[n-1]); //switch has been used to denote cases where the else{ switch(n%10) { case 1://n%10 = 1 print suffix = st System.out.println("The " + n + "st Fibonacci number is: "+ answers[n-1]); break; case 2://n%10 = 2 print suffix = nd System.out.println("The " + n + "nd Fibonacci number is: "+ answers[n-1]); break; case 3://n%10 = 3 print suffix = rd System.out.println("The " + n + "rd Fibonacci number is: "+ answers[n-1]); break; default: //else print suffix = th System.out.println("The " + n + "th Fibonacci number is: "+ answers[n-1]); } } } } public Fibonacci(int num) { this.fib = new long[num]; new Thread(this).start(); try { Thread.sleep(10); } catch (InterruptedException exception) {} } public void run() { synchronized (this.fib) { this.fib[0] = 1; this.fib[1] = 1; for (int i = 2; i < this.fib.length; i++) { this.fib[i] = this.fib[i - 1] + this.fib[i - 2]; } } } public long[] getFib() { return this.fib; } }

Thanks for your time and help.