-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMythread7X.java
More file actions
85 lines (70 loc) · 1.6 KB
/
Mythread7X.java
File metadata and controls
85 lines (70 loc) · 1.6 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
81
82
83
84
85
import java.lang.*;
import java.util.*;
class Marvellous
{
public int Arr[];
public Marvellous(int size)
{
Arr = new int[size];
}
public void Accept()
{
Scanner sobj = new Scanner(System.in);
System.out.println("Enter numbers");
for(int i = 0; i < this.Arr.length; i++)
{
this.Arr[i] = sobj.nextInt();
}
}
public void Display()
{
System.out.println("Data from array is : ");
for(int i = 0; i < this.Arr.length; i++)
{
System.out.println(this.Arr[i]);
}
}
public void DisplayEven()
{
for(int i = 0; i < this.Arr.length; i++)
{
if(this.Arr[i] % 2 == 0)
{
System.out.println(this.Arr[i]);
}
}
}
}
class Demo extends Thread
{
public Marvellous mref;
public Demo(Marvellous obj)
{
this.mref = obj;
}
public void run()
{
this.mref.DisplayEven();
}
}
class Mythread7X
{
public static void main(String ar[]) throws Exception
{
Marvellous mobj1 = new Marvellous(5);
Marvellous mobj2 = new Marvellous(8);
mobj1.Accept();
mobj1.Display();
mobj2.Accept();
mobj2.Display();
Demo dobj1 = new Demo(mobj1);
Demo dobj2 = new Demo(mobj2);
Thread t1 = new Thread(dobj1);
Thread t2 = new Thread(dobj2);
t1.start();
t2.start();
t1.join();
t2.join();
System.out.println("End of main thread");
}
}