-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathW5Q1.java
More file actions
48 lines (44 loc) · 1016 Bytes
/
W5Q1.java
File metadata and controls
48 lines (44 loc) · 1016 Bytes
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
/**
* W5Q1
*/
class ThreadPrime extends Thread {
static boolean isPrime(int n) {
if (n == 2)
return true;
for (int i = 2; i <= n / 2 + 1; i++) {
if (n % i == 0)
return false;
}
return true;
}
public void run() {
for (int i = 2; i <= 100; i++) {
if (isPrime(i)) {
System.out.println(i);
try {
Thread.sleep(500);
} catch (Exception e) {
}
}
}
}
}
class Thread2 extends Thread {
public void run() {
for (int i = 1; i <= 100; i++) {
if (i % 12 == 0) {
System.out.println(i);
try {
Thread.sleep(500);
} catch (Exception e) {
}
}
}
}
}
public class W5Q1 {
public static void main(String[] args) {
ThreadPrime t1 = new ThreadPrime();
t1.start();
}
}