Write a java program to create two threads. One using runnable interface and other by extending thread. First thread will print all odd numbers and second will print all even numbers between 1 to 10

0
555
Want create site? Find Free WordPress Themes and plugins.
 /*Write a java program to create two threads. One using runnable interface
and other by extending thread. First thread will print all odd numbers and
second will print all even numbers between 1 to 10.*/
class odd extends Thread
{
public void run()
{
for(int i=0;i<10;i++)
{
if(i%2!=0)
{
System.out.println(i);
}
}
}
}
class even implements Runnable
{
public void run()
{
for(int i=0;i<10;i++)
{
if(i%2==0)
{
System.out.println(i);
}
}
}
}
public class A
{
public static void main(String args[])
{
even obj=new even();
Thread tobj=new Thread(obj);
odd o=new odd();
Thread t1=new Thread(o);
tobj.start();
t1.start();
}
}
Did you find apk for android? You can find new Free Android Games and apps.

LEAVE A REPLY