-
Notifications
You must be signed in to change notification settings - Fork 0
/
FindMaxAndMin.java
38 lines (34 loc) · 901 Bytes
/
FindMaxAndMin.java
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
import java.util.Scanner;
public class FindMaxAndMin {
public static void main(String[] args) {
int i;
Scanner sc=new Scanner(System.in);
System.out.println("Enter the Size of array=");
int n=sc.nextInt();
int arr[]=new int[n];
System.out.println("Enter the Elemets");
for(i=0;i<n;i++)
{
arr[i]=sc.nextInt();
}
System.out.println("Array are=");
for(i=0;i<n;i++)
{
System.out.print(arr[i] +",");
}
System.out.println();
int min=arr[0];
int max=arr[0];
for(i=0;i<n;i++)
{
if(arr[i]< min){
min =arr[i];
}
if(arr[i]> max){
max=arr[i];
}
}
System.out.println("Maximum="+max);
System.out.println("Minimum="+min);
}
}