-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmaxmin.java
More file actions
43 lines (43 loc) · 1018 Bytes
/
Copy pathmaxmin.java
File metadata and controls
43 lines (43 loc) · 1018 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
35
36
37
38
39
40
41
42
43
package array;
import java.util.Scanner;
public class maxmin {
public static int max(int a[],int n)
{
int x=a[0];
for(int i=1;i<a.length;i++)
{
if(x<a[i])
{
x=a[i];
}
}
return x;
}
public static int min(int a[],int n)
{
int x=a[0];
for(int i=1;i<a.length;i++)
{
if(x>a[i])
{
x=a[i];
}
}
return x;
}
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
int n;
System.out.println("enter number of elements");
n=s.nextInt();
int ar[]=new int[n];
for(int i=0;i<n;i++)
{
ar[i]=s.nextInt();
}
int max=max(ar,n);
int min=min(ar,n);
System.out.println("the maximum element is: "+max);
System.out.println("the minimum element is: "+min);
}
}