Skip to content

Commit 7c69df1

Browse files
committed
Updated
1 parent ada006d commit 7c69df1

3 files changed

Lines changed: 61 additions & 0 deletions

File tree

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/**
2+
* Student: Rustam Zokirov ID: U1910049 Lab: #10
3+
*/
4+
5+
class ThreadPrime extends Thread {
6+
public void run() {
7+
int ct = 0, n = 0, i = 1, j = 1;
8+
while (n < 10) {
9+
j = 1;
10+
ct = 0;
11+
while (j <= i) {
12+
if (i % j == 0)
13+
ct++;
14+
j++;
15+
}
16+
if (ct == 2) {
17+
System.out.println("Prime: " + i);
18+
n++;
19+
}
20+
i++;
21+
try {
22+
Thread.sleep(500);
23+
} catch (InterruptedException e) {
24+
// TODO Auto-generated catch block
25+
e.printStackTrace();
26+
}
27+
}
28+
}
29+
}
30+
31+
class ThreadNonPrime extends Thread {
32+
public void run() {
33+
int x = 18; //end of the interval
34+
int y = 2; //first of the interval
35+
for(int i = y + 1; i < x; i++) {
36+
for(int j = 2; j < i; j++) {
37+
if((i % j ==0 )) {
38+
System.out.println("Non-Prime: " + i);
39+
break;
40+
}
41+
}
42+
try {
43+
Thread.sleep(500);
44+
} catch (InterruptedException e) {
45+
// TODO Auto-generated catch block
46+
e.printStackTrace();
47+
}
48+
}
49+
50+
}
51+
}
52+
53+
public class PrimeNum {
54+
public static void main(String[] arg) {
55+
ThreadPrime thread1 = new ThreadPrime();
56+
ThreadNonPrime thread2 = new ThreadNonPrime();
57+
58+
thread1.start();
59+
thread2.start();
60+
}
61+
}
24.9 KB
Binary file not shown.
28.3 KB
Loading

0 commit comments

Comments
 (0)