interface Test { public abstract boolean check(int n); } public class LambdaTest { public static void main(String[] args) { Test t = (n) -> (n%2)==0; // Test t = (int n) -> (n%2)==0; // Test t = n -> (n%2)==0; java.util.Scanner scan = new java.util.Scanner(System.in); System.out.println("Enter a number: "); int x = scan.nextInt(); System.out.println(x + " is even? " + t.check(x)); x = scan.nextInt(); System.out.println(x + " is even? " + t.check(x)); t = (n) -> n >= 0; x = scan.nextInt(); System.out.println(x + " is non-negative? " + t.check(x)); x = scan.nextInt(); System.out.println(x + " is non-negative? " + t.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