-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMultiThread.java
More file actions
80 lines (61 loc) · 1.46 KB
/
Copy pathMultiThread.java
File metadata and controls
80 lines (61 loc) · 1.46 KB
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
import java.util.Scanner;
class MultiplicationTable{
public synchronized. void printTable(int number){
for(int i=1;i<=10;i++) {
System.out.println(number+"x"+i+"="+i*number);
}
System.out.println(" ");
}
}
class MyThread1 extends Thread{
MultiplicationTable t=new MultiplicationTable();
int num;
MyThread1(int num,MultiplicationTable t){
this.num=num;
this.t=t;
}
public void run() {
t.printTable(num);
}
}
class MyThread2 extends Thread{
MultiplicationTable t=new MultiplicationTable();
int num;
MyThread2(int num,MultiplicationTable t){
this.num=num;
this.t=t;
}
public void run() {
t.printTable(num);
}
}
class MyThread3 extends Thread{
MultiplicationTable t=new MultiplicationTable();
int num;
MyThread3(int num,MultiplicationTable t){
this.num=num;
this.t=t;
}
public void run() {
t.printTable(num);
}
}
public class MultiThread {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
System.out.println("Enter the table you want to run by Thread1 :");
int n=sc.nextInt();
System.out.println("Enter the table you want to run by Thread2 :");
int n2=sc.nextInt();
System.out.println("Enter the table you want to run by Thread3 :");
int n3=sc.nextInt();
MultiplicationTable m=new MultiplicationTable();
MyThread1 t=new MyThread1(n,m);
t.start() ;
MyThread2 t2=new MyThread2(n2,m);
t2.start() ;
MyThread3 t3=new MyThread3(n3,m);
t3.start() ;
sc.close();
}
}