-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEvenNumbers.java
More file actions
43 lines (32 loc) · 1.18 KB
/
EvenNumbers.java
File metadata and controls
43 lines (32 loc) · 1.18 KB
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
import java.util.Scanner;
import java.util.ArrayList;
class EvenNumbers {
public ArrayList<Integer> evenNumbers(ArrayList<Integer> arr){
ArrayList<Integer> result= new ArrayList<>();
for(int i=0;i<arr.size();i++){
Integer new_comment= arr.get(i);
if(new_comment%2 == 0){
result.add(new_comment);
}
}
return result;
}
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
EvenNumbers obj= new EvenNumbers();
System.out.println("Enter the number of elemnts in ArrayList");
int n = sc.nextInt();
sc.nextLine();
ArrayList<Integer> arr= new ArrayList<>();
for(int i=0;i<n;i++){
System.out.println("Enter the number at "+ i + " :-");
Integer comment= sc.nextInt();
arr.add(comment);
}
ArrayList<Integer> result= obj.evenNumbers(arr);
for(Integer num : result){
System.out.println("The Even No.'s are as follows :- ");
System.out.print(num + " ");
}
}
}