-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathExp07.java
151 lines (136 loc) · 2.12 KB
/
Exp07.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import java.util.*;
class ThreadDemo extends Thread
{
String[] a;
int n;
String threadName;
public ThreadDemo()
{
Scanner sc = new Scanner(System.in);
System.out.println("\nEnter the name of the thread: ");
threadName = sc.nextLine();
System.out.println("Enter the size of the array: ");
n = sc.nextInt();
a = new String[n];
for(int i = 0; i < n; i++)
{
System.out.println("Enter the string ");
a[i] = sc.next();
}
}
public void run()
{
System.out.println("\n");
System.out.println("Thread "+threadName+" Start");
try
{
for(int i = 0; i < n; i++)
{
System.out.println(a[i]);
Thread.sleep(100);
}
}
catch(Exception e)
{
}
}
}
class Exp07
{
public static void main(String[] args)
{
ThreadDemo x = new ThreadDemo();
ThreadDemo y = new ThreadDemo();
x.start();
y.start();
try
{
for(int i = 0; i < 10; i++)
{
System.out.println("main thread active");
Thread.sleep(200);
}
}
catch(Exception e)
{
}
}
}
/* OUTPUT
Enter the name of the thread:
Days
Enter the size of the array:
7
Enter the string
Sunday
Enter the string
Monday
Enter the string
Tuesday
Enter the string
Wednesday
Enter the string
Thursday
Enter the string
Friday
Enter the string
Saturday
Enter the name of the thread:
Months
Enter the size of the array:
12
Enter the string
January
Enter the string
February
Enter the string
March
Enter the string
April
Enter the string
May
Enter the string
June
Enter the string
July
Enter the string
August
Enter the string
September
Enter the string
October
Enter the string
November
Enter the string
December
Thread Months Start
January
main thread active
Thread Days Start
Sunday
February
Monday
main thread active
March
Tuesday
April
Wednesday
main thread active
Thursday
May
Friday
June
main thread active
Saturday
July
August
main thread active
September
October
main thread active
November
December
main thread active
main thread active
main thread active
main thread active */