This repository was archived by the owner on Jan 28, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathWeek0505.java
More file actions
67 lines (55 loc) · 2.07 KB
/
Copy pathWeek0505.java
File metadata and controls
67 lines (55 loc) · 2.07 KB
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
59
60
61
62
63
64
65
66
67
package javaaplication5;
import java.util.Collections;
import java.util.List;
public class Week0505 extends Thread {
public static int[] randomNumber = new int[1000000];
public static void main(String[] args) {
for (int i = 0; i < randomNumber.length; i++) {
randomNumber[i] = (int) (Math.round(Math.random()*1000000));
}
new Thread() {
double sum = 0;
public void run() {
for (int i = 0; i < randomNumber.length; i++) {
sum += randomNumber[i];
}
double mean = (double) sum / (double) randomNumber.length;
System.out.println("MIN = " + mean);
}
}.start();
new Thread() {
int mod = 0;
public void run() {
for (int i = 0; i < randomNumber.length; i++) {
if (mod < randomNumber[i]) {
mod = randomNumber[i];
}
}
System.out.println("MOD = " + mod);
}
}.start();
new Thread() {
public void run() {
int temp = 0;
for (int i = 0; i < randomNumber.length; i++) {
for (int j = i + 1; j < randomNumber.length; j++) {
if (randomNumber[i] > randomNumber[j]) {
temp = randomNumber[i];
randomNumber[i] = randomNumber[j];
randomNumber[j] = temp;
}
}
}
int median = 0;
if (randomNumber.length % 2 == 0) {
int firstIndex = randomNumber.length % 2;
int secondIndex = firstIndex + 1;
median = (randomNumber[firstIndex] + randomNumber[secondIndex]) / 2;
} else {
median = randomNumber[randomNumber.length / 2];
}
System.out.println("MEDIAN = " + median);
}
}.start();
}
}