-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLabExp14.java
99 lines (82 loc) · 1.78 KB
/
LabExp14.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import java.util.*;
class Table
{
synchronized void printTable(int n)
{
for(int i=1;i<=5;i++)
{
System.out.println(n+"*"+i+"="+n*i);
try
{
Thread.sleep(1000);
}
catch(Exception e)
{
System.out.println(e);
}
}
}
}//end of the method
class MyTaba extends Thread
{
int d ;
Table t;
int g;
MyTaba(Table t,int g)
{
this.t=t;
d=g;
}
public void run( )
{
t.printTable(d);
}
}
class MyTabn extends Thread
{
int e;
Table t;
MyTabn(Table t,int f)
{
this.t=t;
e=f;
}
public void run()
{
t.printTable(e);
}
}
class MyTab3 extends Thread
{
int p;
Table t;
MyTab3(Table t,int q)
{
this.t=t;
p=q;
}
public void run()
{
t.printTable(p);
}
}
public class LabExp14 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the table to be found first");
int c =sc.nextInt();
System.out.println("Enter the table to be found second");
int n =sc.nextInt();
System.out.println("Enter the table to be found third");
int m =sc.nextInt();
Table obj = new Table();//only one object
MyTaba s = new MyTaba(obj,c);
MyTabn t=new MyTabn(obj,n);
MyTab3 o =new MyTab3(obj,m);
s.start();
// o.start();
t.start();
o.start();
sc.close();
}
}