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));
}
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter