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