-
Notifications
You must be signed in to change notification settings - Fork 549
Expand file tree
/
Copy pathDesafio15.java
More file actions
24 lines (21 loc) · 845 Bytes
/
Desafio15.java
File metadata and controls
24 lines (21 loc) · 845 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
package stream_api;
import java.util.Arrays;
import java.util.List;
/*
* Verifique se a lista contém pelo menos um número negativo:
* Utilizando a Stream API, verifique se a lista contém pelo menos um número
* negativo e exiba o resultado no console.
*/
public class Desafio15 {
public static void main(String[] args) {
System.out.println(
"---15- VERIFICAR SE EXISTE NUMERO NEGATIVO ---");
List<Integer> numeros = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 5, 4, 3);
List<Integer> numerosNegativos = numeros.stream().filter(n -> n < 0).toList();
if (numerosNegativos.isEmpty()) {
System.out.println("Não existem números negativos nesta lista.");
} else {
System.out.println("Números negativos da lista: " + numerosNegativos);
}
}
}