Question: Write a Java program that makes use of the following methods from the String class: boolean contains (Links to an external site.)Links to an external

Write a Java program that makes use of the following methods from the String class:

boolean contains (Links to an external site.)Links to an external site.(CharSequence (Links to an external site.)Links to an external site. s)

Returns true if and only if this string contains the specified sequence of char values.

boolean endsWith (Links to an external site.)Links to an external site.(String (Links to an external site.)Links to an external site. suffix)

Tests if this string ends with the specified suffix.

String (Links to an external site.)Links to an external site. replace (Links to an external site.)Links to an external site.(CharSequence (Links to an external site.)Links to an external site. target, CharSequence (Links to an external site.)Links to an external site. replacement)

Replaces each substring of this string that matches the literal target sequence with the specified literal replacement sequence.

String (Links to an external site.)Links to an external site. toLowerCase (Links to an external site.)Links to an external site.()

Converts all of the characters in this String to lower case using the rules of the default locale.

Starter Code (you can copy and paste):

public class StringFun { public static void main( String[] args ) { String woodchuck = "How much wood would a woodchuck chuck if a wood chuck could chuck wood?"; String bard = "A fool thinks himself to be wise, but a wise man knows himself to be a fool."; // Check if the first string contains "woodchuck" System.out.println( woodchuck.contains( "woodchuck" ) ); // Check if the bard string contains "star" // Check if the woodchuck string ends with "chuck wood" // Check if the bard string ends with "fool" // In string woodchuck, replace all instances of "woodchuck" with "groundhog" // Display string bard in all lower case } }

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!