-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMaxMin_Simple.java
More file actions
34 lines (25 loc) · 856 Bytes
/
MaxMin_Simple.java
File metadata and controls
34 lines (25 loc) · 856 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
34
import java.util.Scanner;
public class MaxMin_Simple {
static void max_min(int[] arr, int n, int start, int end){
int max = arr[0], min = arr[0];
for(int i : arr){
if(i>=max)
max=i;
if(i<=min)
min=i;
}
System.out.println("Maximum element is : "+ max);
System.out.println("Minimum element is : "+ min);
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the size of the array : ");
int n = sc.nextInt();
int[] arr = new int[n];
System.out.println("Enter the elements of the array : ");
for (int i = 0; i < n; i++) {
arr[i] = sc.nextInt();
}
max_min(arr, arr.length, 0, arr.length-1);
}
}