-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathMinimumEvenInArray.java
More file actions
37 lines (36 loc) · 822 Bytes
/
Copy pathMinimumEvenInArray.java
File metadata and controls
37 lines (36 loc) · 822 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
/* Find the even number in an array which is minimum. If not found then print -1.
*
* Input:
* ---------------
* 5
* 5 4 7 3 9 12
*
* Output:
* ---------------
* 4
*/
import java.util.*;
public class MinimumEvenInArray {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] arr = new int[n];
for (int i = 0; i < arr.length; i++) {
arr[i] = sc.nextInt();
}
Arrays.sort(arr);
boolean f = true;
for (int i = 0; i < arr.length; i++) {
if(arr[i]%2==0)
{
System.out.println(arr[i]);
f = false;
break;
}
}
if(f==true)
{
System.out.println(-1);
}
}
}