Skip to main content

Demonstration of threads in java by printing table of numbers

import java.lang.*;
class Threadx extends Thread
{
public void run()
{
int i;
try
{
for(i=1;i<11;i++)
{
Thread.sleep(1000);
System.out.println("2*"+i+"="+(2*i));
}
}
catch(Exception e)
{
System.out.println(e);
}
}
}
class Thready extends Thread
{
public void run()
{
int i;
try
{
for(i=1;i<11;i++)
{
Thread.sleep(3000);
System.out.println("\t3*"+i+"="+(3*i));
}
}
catch(Exception e)
{
System.out.println(e);
}
}
}

class Threadz extends Thread
{
public void run()
{
int i;
try
{
for(i=1;i<11;i++)
{
Thread.sleep(2000);
System.out.println("\t\t4*"+i+"="+(4*i));
}
}
catch(Exception e)
{
System.out.println(e);
}
}
}

class Table

{
public static void main(String args[])
{
Threadx ob=new  Threadx();
ob.start();

Thready ob2=new  Thready();
ob2.start();
Threadz ob3=new  Threadz();
ob3.start();

}
}

Comments

Popular posts from this blog

unix commands