Tuesday, 4 March 2025

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


class NumberThread extends Thread 

{

    public void run()

     {

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

         {

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

 try {

 Thread.sleep(100);

 } 

catch (InterruptedException e)

 { 

e.printStackTrace(); 

}        }    }}

class AlphabetThread extends Thread

 {

    public void run() {

        for (char ch = 'a'; ch <= 'z'; ch++) 

{

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

  try 

Thread.sleep(100);

 } 

catch (InterruptedException e) 

e.printStackTrace(); 

}        }    }}


class VowelThread extends Thread {

    public void run() {

        char[] vowels = {'a', 'e', 'i', 'o', 'u'};

        for (char v : vowels) {

            System.out.println("Vowel: " + v);

            try

 { 

Thread.sleep(200); 

catch (InterruptedException e) 

{  e.printStackTrace(); }        }    }}


public class MultiThreadExample 

{

    public static void main(String[] args) {

        NumberThread t1 = new NumberThread();

        AlphabetThread t2 = new AlphabetThread();

        VowelThread t3 = new VowelThread();

        t1.start();

        t2.start();

        t3.start();

    } }