-
Notifications
You must be signed in to change notification settings - Fork 0
/
MaxMin.java
37 lines (26 loc) · 856 Bytes
/
MaxMin.java
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
import java.util.Scanner;
public class MaxMin {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
int n, num, max = 0, min = 0;
System.out.println("How many numbers will you entered ? : ");
n = keyboard.nextInt();
for (int i = 1; i <= n; i++) {
do {
System.out.println("Please input the " + i + ". number: ");
num = keyboard.nextInt();
}
while (num < 0);
if (num > max) {
if (min == 0) {
min = num;
}
max = num;
} else if (num < min) {
min = num;
}
}
System.out.println("Minimum Number is : "+min);
System.out.println("Maximum Number is : "+max);
}
}