-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMultitable.java
More file actions
43 lines (37 loc) · 931 Bytes
/
Copy pathMultitable.java
File metadata and controls
43 lines (37 loc) · 931 Bytes
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
package java3;
class MultiplicationTable{
synchronized void printMultiplicationtable(int number) {
for(int i=1;i<=10;i++) {
System.out.println(i+"x"+number+"="+i*number);
}
}
}
class MyThread1 extends Thread{
MultiplicationTable t=new MultiplicationTable();
MyThread1(MultiplicationTable t){
this.t=t;
}
public void run() {
System.out.println(Thread.currentThread().getName());
t.printMultiplicationtable(5);
}
}
class Mythread2 extends Thread{
MultiplicationTable t;
Mythread2(MultiplicationTable t){
this.t=t;
}
public void run() {
System.out.println(Thread.currentThread().getName());
t.printMultiplicationtable(7);
}
}
public class Multitable {
public static void main(String[] args) {
MultiplicationTable m=new MultiplicationTable();
MyThread1 t=new MyThread1(m);
Mythread2 t2=new Mythread2(m);
t.start();
t2.start();
}
}