-
Notifications
You must be signed in to change notification settings - Fork 0
/
NumberThread.java
38 lines (33 loc) · 1009 Bytes
/
NumberThread.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
class NumberThread extends Thread {
private int start;
private int end;
public NumberThread(int start, int end) {
this.start = start;
this.end = end;
}
public void run() {
try {
for (int i = start; i <= end; i++) {
boolean isPrime = true;
if (i > 1) {
for (int j = 2; j <= Math.sqrt(i); j++) {
if (i % j == 0) {
isPrime = false;
break;
}
}
} else {
isPrime = false;
}
if (isPrime) {
System.out.println("O numero " + i + " eh primo");
} else {
System.out.println("O numero " + i + " nao eh primo");
}
Thread.sleep(700);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}