-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththreads.java
39 lines (32 loc) · 1005 Bytes
/
threads.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
import javax.swing.JOptionPane;
class threads{
public static void main(String[] args) {
Runnable countEven = () -> {
int even = 0;
for (int i = 1; i < 10000; i++) {
if(i % 2 == 0)
{
even = even + 1;
}
}
JOptionPane.showMessageDialog(null,"even count ==> "+even);
};
Runnable countPrime = () -> {
int prime = 0;
for(int i = 1 ; i <= 10000 ; i++)
{
int count = 0;
for(int j = 1 ; j <= i ; j++)
{
if(i % j == 0)
count = count+1;
}
if(count == 2)
prime = prime + 1;
}
JOptionPane.showMessageDialog(null,"prime count ==> "+prime);
};
new Thread (countEven).start();
new Thread (countPrime).start();
}
}