-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEx2.java
More file actions
34 lines (32 loc) · 954 Bytes
/
Copy pathEx2.java
File metadata and controls
34 lines (32 loc) · 954 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
package Arrays;
import java.util.Locale;
import java.util.Random;
import java.util.Scanner;
public class Ex2 {
public static void main(String[] args) {
Locale.setDefault(Locale.US);
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
long seed = scan.nextLong();
double[] a = new double[n];
Random rand = new Random(seed);
for (int i = 0; i < a.length; i++) {
a[i] = rand.nextDouble(0, 5);
System.out.printf("%.2f ", a[i]);
}
System.out.println();
double sum = 0;
for (int x = 0; x< a.length; x++) {
sum +=a[x];
}
sum/=n;
System.out.printf("%.2f", sum);
System.out.println();
for (int b=0; b<a.length; b++) {
if (a[b]>sum) {
a[b]=sum;
}
System.out.printf("%.2f ", a[b]);
}
}
}