-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMinMax1.java
More file actions
23 lines (18 loc) · 620 Bytes
/
MinMax1.java
File metadata and controls
23 lines (18 loc) · 620 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package minmax;
import java.util.Scanner;
public class MinMax1 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n, min = Integer.MAX_VALUE, max = Integer.MIN_VALUE;
System.out.print("n = ");
n = scanner.nextInt();
for (int i = 1; i <= n; i++) {
System.out.print(i + " = ");
int number = scanner.nextInt(); // i=1
if (min > number) min = number; // min = 5
if (max < number) max = number; // max = 5
}
System.out.println(max);
System.out.println(min);
}
}