forked from stefanandonov/SI2023
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSILab1.java
41 lines (33 loc) · 964 Bytes
/
SILab1.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
39
40
41
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class SILab1 {
public static List<Integer> filterOddNumbers(List<Integer> list) {
List<Integer> result = new ArrayList<>();
for (Integer el : list) {
if (el % 2 == 0) {
result.add(el);
}
}
return result;
}
private static int sumEvenNumbers(List<Integer> list) {
int sum = 1;
for (Integer el : list) {
if (el % 2 == 0) {
sum *= el;
}
}
return sum;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
List<Integer> list = new ArrayList<>();
for (int i = 0; i <= n; i++) {
list.add(sc.nextInt());
}
System.out.println(filterOddNumbers(list));
System.out.println(sumEvenNumbers(list));
}
}