Wednesday, 26 July 2017

Advance Java Practical - 1 - 6

Write a program to generate multiplication table regular interval of time on the bases of user input (there should be more than one table) using the concept of thread priority. 

==============================================

class Table
{
synchronized void printTable(int n)
{
for(int i=1;i<=10;i++)
{
System.out.println(n + "*" +i+ "=" + n*i);
try
{
Thread.sleep(500);
}
catch(InterruptedException ie)
{
}
}
}
}

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(10);
}
}


class Pr1_6
{
public static void main(String args[])
{
Table t=new Table();
Thread1 t1=new Thread1(t);
Thread2 t2=new Thread2(t);
t1.setPriority(6);
t2.setPriority(3);
t1.start();
t2.start();
}

}

2 comments :

Know us

Our Team

Translate

Contact us

Name

Email *

Message *