- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathminmax.java
More file actions
Latest commit
33 lines (29 loc) · 805 Bytes
/
Copy pathminmax.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
importjava.util.Scanner;
publicclassminmax {
publicstaticvoidmain(String[] args) {
intn;
System.out.println("how many number will you enter ?");
Scannerinp = newScanner(System.in);
n = inp.nextInt();
intmin = 0, max = 0;
intnum;
for (inti = 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();
}
}