Tuesday, 4 March 2025

Write a java program to create the following threads. a) To print from 100 to 1. b) To print alphabet z to a c)To even number from 1 to 100.



import java.lang.*;


//  to print numbers from 100 to 1

class NumberThread extends Thread

{

    public void run()

    {

        for(int i = 100; i >= 1; i--)

        {

            System.out.println("Number : " + i);

        }

    }

}


// to print alphabets from z to a

class AlphabetThread extends Thread

{

    public void run()

    {

        for(char ch = 'z'; ch >= 'a'; ch--)

        {

            System.out.println("Alphabet : " + ch);

        }

    }

}




//  to print even numbers from 1 to 100

class EvenThread extends Thread

{

    public void run()

    {

        for(int i = 2; i <= 100; i = i + 2)

        {

            System.out.println("Even Number : " + i);

        }

    }

}



class ThreadExample

{

    public static void main(String args[])

    {

        NumberThread t1 = new NumberThread();

        AlphabetThread t2 = new AlphabetThread();

        EvenThread t3 = new EvenThread();


        t1.start();

        t2.start();

        t3.start();

    }

}