Home Top Ad

Java - Create Threads




Write a program that has four threads. First thread should calculate the square of a number. Second thread calculates the volume of cylinder. Third thread calculates an area of triangle while the other thread should print student’s details. Set the priority of the four thread to display first.


import java.awt.*;

class A extends Thread
{
    public void run()
    {
        System.out.println("NAME : AHMAD AZIZUL");
        System.out.println("CLASS : DIP");
        System.out.println("COURSE : PROGRAMMING");
    }
}

class B extends Thread
{
    public void run()
    {
        Integer s;
        s=3*3;
        System.out.println("Square of 3 is : "+s);
    }
}

class C extends Thread
{
    public void run()
    {
        final double h=0.5;
        double t;
        t=h*20*2;
        System.out.println("Area of triangle is : "+t);
    }
}

class D extends Thread
{
    public void run()
    {
        final double pi=3.142;
        double d;
        d=pi*2*2*6;
        System.out.println("Cylinder volume : "+d);
    }
}
Java - Create Threads Java - Create Threads Reviewed by FJ on 4:45 PM Rating: 5

No comments