Question: import java.util.function. * ; class PredicateMethods { public static void result ( Predicate p , Integer arg ) { if ( p . test (

import java.util.function.*;
class PredicateMethods
{
public static void result(Predicate p, Integer arg)
{
if (p.test(arg))
System.out.printf("The Predicate is true for %d
", arg);
else
System.out.printf("The Predicate is false for %d
", arg);
}
public static void main(String [] args)
{
Predicatep1= x->x ==5;
for (int x =4; x <7; x++)
{
result(p1,x);
result(y->y%2==0, x);
}
}
}
PredicateMethodsGeneric (20)
Modify PredicateMethods from Programs/Lesson 13/Classwork to make the type generic. Call it PredicateMethodsGeneric.
Add a Predicate p3 of type String that tests if the first character of a String is H. Then test with a String where the first character is H, and one where it isnt.
Sample Output:
The Predicate is false for 4
The Predicate is true for 4
The Predicate is true for 5
The Predicate is false for 5
The Predicate is false for 6
The Predicate is true for 6
The Predicate is true for Hello
The Predicate is false for Goodbye

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!