forked from AdeshTikande/Basic-Java-Program-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMinmax.java
More file actions
26 lines (18 loc) · 694 Bytes
/
Copy pathMinmax.java
File metadata and controls
26 lines (18 loc) · 694 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
import java.util.Scanner;
public class Minmax {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter number of elements: ");
int n = sc.nextInt();
int[] arr = new int[n];
System.out.println("Enter elements:");
for (int i = 0; i < n; i++) arr[i] = sc.nextInt();
int min = arr[0], max = arr[0];
for (int i=0;i<=arr.length-1;i++) {
if (arr[i]< min) min =arr[i];
if (arr[i] > max) max = arr[i];
}
System.out.println("Minimum: " + min);
System.out.println("Maximum: " + max);
}
}