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.


class PrintNumbersThread extends Thread {

    public void run() {

        // Task a) Print numbers from 100 to 1

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

            System.out.println(i);

        }

    }

}

class PrintAlphabetsThread extends Thread {

    public void run() {

        // Task b) Print alphabets from z to a

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

            System.out.println(ch);

        }

    }

}

class PrintEvenNumbersThread extends Thread {

    public void run() {

        // Task c) Print even numbers from 1 to 100

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

            System.out.println(i);

        }

    }

}


public class Main {

    public static void main(String[] args) {

        // Create instances of the threads

        Thread t1 = new PrintNumbersThread();

        Thread t2 = new PrintAlphabetsThread();

        Thread t3 = new PrintEvenNumbersThread();

        // Start the threads

        t1.start();

        t2.start();

        t3.start();

    }

}