Write a program to create two threads.so one thread will print even numbers between 1 to 10 whereas other will print odd number between 11 to 20 in java

class eventhread extends Thread
{
 public void run()
{
 for(int i=1;i<=10;i=i+2)
{
 System.out.println("Even no="+ i);
 }
}
}
class oddthread extends Thread
{
 public void run()
{ for(int i=11;i<=20;i=i+2)
 {
 System.out.println("Odd no="+ i);
 }
 }
 }
 class threadtest
{
 public static void main(String args[]) {
 eventhread e1= new eventhread();
 oddthread o1= new oddthread();
e1.start(); o1.start();
}
}
 Output: E:\java\bin>javac threadtest.java
E:\java\bin>java threadtest
Odd no=11
Even no=2
Odd no=13
Odd no=15
 Even no=4
Even no=6
Odd no=17
Odd no=19
Even no=8
Even no=10

Comments