-
Notifications
You must be signed in to change notification settings - Fork 546
Expand file tree
/
Copy pathDesafio19.java
More file actions
27 lines (17 loc) · 863 Bytes
/
Desafio19.java
File metadata and controls
27 lines (17 loc) · 863 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
package stream_api;
import java.util.Arrays;
import java.util.List;
public class Desafio19 {
public static void main(String[] args) {
/*- Desafio 19 - Encontre a soma dos números divisíveis por 3 e 5:
Com a Stream API, encontre a soma dos números da lista que são divisíveis tanto por 3 quanto por 5 e exiba o resultado no console. */
List<Integer> numeros = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 5, 4, 3);
List<Integer> divisivel = numeros.stream()
.filter(n -> n % 3 == 0 && n %5 == 0)
.toList();
int soma = divisivel.stream()
.reduce(0, (a, b) -> a + b);
System.out.println("Divisível de 3 e 5 (15): " + divisivel);
System.out.println("Soma: " + soma);
}
}