class Table
{
public synchronized void printtable(int n)
{
for(int i=1;i<=10;i++)
{
System.out.println(n+"X"+i+"="+(n*i));
}
}
}
class Thread1 extends Thread
{
Table t;
Thread1(Table t)
{
this.t=t;
}
public void run()
{
t.printtable(5);
}
}
class Thread2 extends Thread
{
Table t;
Thread2(Table t)
{
this.t=t;
}
public void run()
{
t.printtable(7);
}
}
class D
{
public static void main(String[] args)
{
Table r= new Table();
Thread1 t1= new Thread1(r);
Thread2 t2= new Thread2(r);
t1.start();
t2.start();
}
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter