-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMinMax23.java
More file actions
51 lines (44 loc) · 1.16 KB
/
MinMax23.java
File metadata and controls
51 lines (44 loc) · 1.16 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
package minmax;
import java.util.Scanner;
public class MinMax23 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n;
int max1=0;
int max2=0;
int max3=0;
int r;
n = scanner.nextInt();
for (int i = 1; i <= n; i++) {
System.out.print(i + ".");
r = scanner.nextInt();
//
if (i == 1) {
max1 = r;
max2 = r;
max3 = r;
}
//
if ((r > max3) && (r != max1) && (r != max2)) {
if (r > max2) {
max3 = max2;
if (r > max1) {
max2 = max1;
max1 = r;
} else {
max2 = r;
}
} else
max3 = r;
}
//
if (max1 == max2) {
max2 = r;
}
if ((max3 == max1) || (max3 == max2)) {
max3 = r;
}
}
System.out.printf("%d , %d, %d",max1,max2,max3);
}
}