. Write a Java multi-threaded programming where user will take a number as input from command line. The program will then create a separate thread that will generate the Fibonacci numbers and stores in an array. When the thread finishes execution, main thread will output the sequence generated by the child thread.


import java.util.ArrayList;
import java.util.Scanner;

public class vinnu12 {

    public static void main(String args[]) {
        Scanner vinnu = new Scanner(System.in);
        ArrayList al = new ArrayList();
        int a;
        System.out.print("Enter the number  : ");
        a = vinnu.nextInt();
        FirstThread firstThread = new FirstThread(a);               //Creating an object of the first thread                  
        firstThread.start();                                        //Starting the first thread

        try {
            firstThread.join();
        } catch (InterruptedException ex) {
        }

        int a3[] = firstThread.arr;                       // a3 = firstThread.carrying();

        for (int i = 0; i < a; i++) {
            System.out.print(a3[i] + " ");
        }

    }
}

class FirstThread extends Thread {

    private int a, i;
    Thread t;
    int arr[];

    public FirstThread(int a) {
        this.a = a;
        arr = new int[a];
    }

    public void run() {
        arr[0] = 1;
        arr[1] = 1;
        for (i = 2; i < a; i++) {

            arr[i] = arr[i - 1] + arr[i - 2];
        }
    }
}

. Write a Java multi-threaded programming where user will take a number as input from command line. The program will then create a separate thread that will generate the Fibonacci numbers and stores in an array. When the thread finishes execution, main thread will output the sequence generated by the child thread. . Write a Java multi-threaded programming where user will take a number as input from command line. The program will then create a separate thread that will generate the Fibonacci numbers and stores in an array. When the thread finishes execution, main thread will output the sequence generated by the child thread. Reviewed by Unknown on 01:54 Rating: 5

No comments:

Powered by Blogger.