Write a program to create two threads one thread will print even no. between 1 to 50 and other will print odd number between 1 to 50.
import java.lang.*;
class Even extends Thread
{
public void run()
{
try
{
for(int i=2;i<=50;i=i+2)
{
System.out.println("\t Even thread :"+i);
sleep(500);
}
}
catch(InterruptedException e)
{System.out.println("even thread interrupted");
}
}
}
class Odd extends Thread
{
public void run()
{
try
{
for(int i=1;i<50;i=i+2)
{
System.out.println("\t Odd thread :"+i);
sleep(500);
}
}
catch(InterruptedException e)
{System.out.println("odd thread interrupted");
}
}
}
class EvenOdd
{
public static void main(String args[])
{
new Even().start();
new Odd().start();
}
}