LAMBDA_TEST

PHOTO EMBED

Wed May 29 2024 13:23:01 GMT+0000 (Coordinated Universal Time)

Saved by @signup

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));
	}
}
content_copyCOPY