-
Notifications
You must be signed in to change notification settings - Fork 0
/
Lab10_U1910060.java
58 lines (52 loc) · 1.2 KB
/
Lab10_U1910060.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
/* Student
ID: U1910060
Name: Abdullokh Alimov
MSC2070-002
*/
// It can be on final exam also !
class threadPrime extends Thread
{
public void run()
{
boolean primeNumber = true; // Initial point
for(int i=1;i<=10;i++){ // Loop for (1 ... 10) numbers generator
for(int j=2;j<=(i/2);j++){ // Prime Checker
if(i%j == 0){
primeNumber = false;
}
}
if (primeNumber || i == 2 || i == 1) { // Prime Printer
System.out.println("Thread Prime: " + i);
}
primeNumber= true;
}
}
}
class threadNonPrime extends Thread
{
public void run()
{
boolean primeNumber = true; // Initial point
for(int i=1;i<=10;i++){ // Loop for (1 ... 10) numbers generator
for(int j=2;j<=(i/2);j++){ // Prime Checker
if(i%j == 0){
primeNumber = false;
}
}
if (primeNumber == false) { // Prime Non Printer
System.out.println("Thread NON-Prime: " + i);
}
primeNumber= true;
}
}
}
public class Lab10_U1910060
{
public static void main(String[] arg)
{
threadPrime t1 = new threadPrime();
threadNonPrime t2 = new threadNonPrime();
t1.start(); // Prime
t2.start(); // Non Prime
}
}