Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

DB2 11 The Ultimate Database For Cloud Analytics And Mobile

Authors: John Campbell, Chris Crone, Gareth Jones, Surekha Parekh, Jay Yothers

1st Edition

1583474013, 978-1583474013

More Books

Students also viewed these Databases questions