LAMBDA EVEN OR NON-NEGATIVE OR TEST

PHOTO EMBED

Wed May 29 2024 16:38:54 GMT+0000 (Coordinated Universal Time)

Saved by @signup

import java.util.Scanner;

interface Test {
    boolean check(int n);
}

public class LambdaTest {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        
        Test isEven = n -> (n % 2) == 0;
        Test isNonNegative = n -> n >= 0;
        
        System.out.print("Enter a number: ");
        int x = scan.nextInt();
        System.out.println(x + " is even? " + isEven.check(x));

        System.out.print("Enter another number: ");
        x = scan.nextInt();
        System.out.println(x + " is non-negative? " + isNonNegative.check(x));
    }
}
content_copyCOPY