Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.List;
- import java.util.stream.Collectors;
- public class HelloWorld{
- public static void main(String []args){
- try {
- List<Integer> numbersWith3Digits = quiz(List.of(22,155,228,3,4555));
- numbersWith3Digits.forEach(System.out::println);
- }catch(Exception e)
- {
- System.out.println(e);
- }
- }
- public static List<Integer> quiz(List<Integer> lista) throws Exception {
- List<Integer> numbersWith3Digits = lista.stream().filter(e -> e.toString().length() > 2).collect(Collectors.toList());
- if(numbersWith3Digits.isEmpty()) {
- throw new Exception ("not any");
- }
- return numbersWith3Digits;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement