когда опубликовывал свой вопрос, увидел спойлер
anyMatch(x->x<0&&x%2==0);
но все же хочу узнать, почему не работает мой фильтр?package com.javarush.task.pro.task18.task1817;
import java.util.stream.Stream;
/*
Анализ потока чисел
*/
public class Solution {
public static void main(String[] args) {
String answerYes = "Yes";
String answerNo = "No";
Stream<Integer> stream1 = Stream.of(10, -22, 3, 12, -85, 0, 142);
String answerNegativeEvenNumbers = hasNegativeEvenNumbers(stream1) ? answerYes : answerNo;
System.out.println("Any negative even numbers in the stream? " + answerNegativeEvenNumbers);
Stream<Integer> stream2 = Stream.of(10, 22, 3, 12, 85, 142);
String answerOnlyPositiveNumbers = hasOnlyPositiveNumbers(stream2) ? answerYes : answerNo;
System.out.println("Only positive numbers in the stream? " + answerOnlyPositiveNumbers);
Stream<Integer> stream3 = Stream.of(-10, -22, -3, -12, -85, -142);
String answerOnlyNegativeNumbers = hasOnlyNegativeNumbers(stream3) ? answerYes : answerNo;
System.out.println("Only negative numbers in the stream? " + answerOnlyNegativeNumbers);
}
public static boolean hasNegativeEvenNumbers(Stream<Integer> stream) {
boolean hasNeg = stream.filter(x -> x%2==0).anyMatch(x->x<0);
return hasNeg;
}
public static boolean hasOnlyPositiveNumbers(Stream<Integer> stream) {
boolean hasPos = stream.allMatch(x->x>0);
return hasPos;
}
public static boolean hasOnlyNegativeNumbers(Stream<Integer> stream) {
boolean onlyNeg = stream.noneMatch(x->x>0);
return onlyNeg;
}
}