-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMinMax10.java
More file actions
36 lines (30 loc) · 940 Bytes
/
MinMax10.java
File metadata and controls
36 lines (30 loc) · 940 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
package minmax;
import java.util.Scanner;
public class MinMax10 {
public static void main(String[] args) {
int n;
int r;
int min = Integer.MAX_VALUE;
int max = Integer.MIN_VALUE;
int minnum = 0;
int maxnum = 0;
Scanner scanner = new Scanner(System.in);
System.out.println("N:");
n = scanner.nextInt();
for (int i = 1; i <= n; ++i) {
System.out.print(i + ".");
r = scanner.nextInt();
if ((i == 1) || (r < min)) {
min = r;
minnum = i;
}
if ((i == 1) || (r > max)) {
max = r;
maxnum = i;
}
}
if (maxnum > minnum) {
System.out.printf("Birinchi uchragan ekstremal: %d\n", minnum);
} else if (minnum > maxnum) System.out.printf("Birinchi uchragan ekstremal: %d\n", maxnum);
}
}