-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathminmax.java
More file actions
33 lines (29 loc) · 805 Bytes
/
minmax.java
File metadata and controls
33 lines (29 loc) · 805 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
import java.util.Scanner;
public class minmax {
public static void main(String[] args) {
int n;
System.out.println("how many number will you enter ?");
Scanner inp = new Scanner(System.in);
n = inp.nextInt();
int min = 0, max = 0;
int num;
for (int i = 1; i <= n; i++) {
System.out.println(i+". num:");
num = inp.nextInt();
if(i == 1){
min = num;
max = num;
}else{
if(num < min){
min = num;
}
if(num > max){
max = num;
}
}
}
System.out.println("min:"+min);
System.out.println("max:"+max);
inp.close();
}
}