-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMinMax21.java
More file actions
53 lines (49 loc) · 1.29 KB
/
MinMax21.java
File metadata and controls
53 lines (49 loc) · 1.29 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
package minmax;
import java.util.Scanner;
public class MinMax21 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int r;
int min = Integer.MAX_VALUE;
int max = Integer.MIN_VALUE;
int sum = 0;
int n;
int counterMax=0;
int counterMin=0;
n = scanner.nextInt();
for (int i = 1; i <= n; i++) {
System.out.print(i + ".");
r = scanner.nextInt();
if (i == 1) {
min = r;
counterMin = 0;
max = r;
counterMax = 0;
}
if (r < min) {
if (min != max) {
sum += min * counterMin;
}
min = r;
counterMin = 0;
//
}
//
if (r > max) {
if (max != min) {
sum += max * counterMax;
}
max = r;
counterMax = 0;
}
//
if (r == min) {
++counterMin;
} else if (r == max)
++counterMax;
else
sum += r;
}
System.out.println(sum / (n - counterMax - counterMin));
}
}