-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMinMaxSumAverage.java
More file actions
50 lines (35 loc) · 925 Bytes
/
MinMaxSumAverage.java
File metadata and controls
50 lines (35 loc) · 925 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
49
50
import java.util.Scanner;
import java.text.DecimalFormat;
public class MinMaxSumAverage {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
double[]arr=new double[n];
for (int i = 0; i < arr.length; i++) {
arr[i]=sc.nextDouble();
}
findMinMaxSumAverage(arr);
}
private static void findMinMaxSumAverage(double[]arr){
double min=10001;
double max=-10001;
double sum=0;
double average=0;
for (int i = 0; i < arr.length; i++) {
if (arr[i]>max) {
max=arr[i];
}
if (arr[i]<min) {
min=arr[i];
}
sum+=arr[i];
average+=arr[i];
}
average/=arr.length;
DecimalFormat df = new DecimalFormat("####0.00");
System.out.println("min="+df.format(min));
System.out.println("max="+df.format(max));
System.out.println("sum="+df.format(sum));
System.out.println("avg="+df.format(average));
}
}