Wednesday, 5 March 2025

Write a JAVA program which will create two child threads by implementing Runnable interface; one thread will print even no’s from 1 to 50 and other display vowels


import java.lang.*;


// to print even numbers

class EvenNumbers implements Runnable

{

    public void run()

    {

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

        {

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

        }

    }

}


//  to print vowels

class Vowels implements Runnable

{

    public void run()

    {

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


        for(int i = 0; i < v.length; i++)

        {

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

        }

    }

}


class RunnableExample

{

    public static void main(String args[])

    {

        EvenNumbers e = new EvenNumbers();

        Vowels v = new Vowels();


        Thread t1 = new Thread(e);

        Thread t2 = new Thread(v);


        t1.start();

        t2.start();

    }

}