Starting Out with Java: From Control Structures through Data Structures (3rd Edition)
3rd Edition
ISBN: 9780134038179
Author: Tony Gaddis, Godfrey Muganda
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 9.4, Problem 9.21CP
Program Plan Intro
String class:
- The “String” class provides a number of methods that examines for a string inside of a string.
- The term “substring” refers to a string that denotes another string’s part.
- The “startsWith” method would determine whether calling string of object begins with a specific substring.
- The method returns “true” if string begins with specified substring, it returns “false” otherwise.
- The “endsWith” method would determine whether calling string would end with a specified substring.
- The method returns “true” if string ends with specified substring, it returns “false” otherwise.
- The “regionMatches” method would determine whether specified regions for two strings match.
- The first argument of this method can be “true” or “false” that indicates whether a case-insensitive comparison could be performed.
StringBuilder class:
- The “StringBuilder” class is same as “String” class except that contents of “StringBuilder” objects could be changed.
- It provides several methods that “String” class does not have.
- The “append” method accepts an argument that might be a primitive data type.
- It appends a string representation to contents of calling object.
- The “insert” method accepts two arguments, an integer that specifies position in string of calling object as well as value to be inserted.
- The “replace” method replaces the occurrences of one character with another character.
- The “toString” method converts a “StringBuilder” object in to a regular string.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Name format: You must use String object and not StringBuffer or StringBuilder.
Many documents use a specific format for a person's name. Write a program that take one
Line as an input.
Example:
Scanner input = new Scanner(System.in);
System.out.println(“Enter firstName middleName lastName separated by at least one
blank, It may have more than one blank separating firstName middleName lastName.");
Input sample : Pat Silly Doe || Note these are separated by at least one blank.
String line = input.nextLine()
Ex: If the input is:
Pat Silly Doe
the output is:
Doe, P.S.
If the input has the form:
firstName lastName
the output is:
lastName, firstInitial.
Ex: If the input is:
Julia Clark
the output is:
Clark, J.
Please submit the .java source file and the sample run in a text file. Thanks
Displaying an enumerator's string value requires what method?
State true or false:
A regular expression enables a quick test to determine objects and text strings with undependable values.
Chapter 9 Solutions
Starting Out with Java: From Control Structures through Data Structures (3rd Edition)
Ch. 9.2 - Prob. 9.1CPCh. 9.2 - Write an if statement that displays the word digit...Ch. 9.2 - Prob. 9.3CPCh. 9.2 - Write a loop that asks the user, Do you want to...Ch. 9.2 - Prob. 9.5CPCh. 9.2 - Write a loop that counts the number of uppercase...Ch. 9.3 - Prob. 9.7CPCh. 9.3 - Modify the method you wrote for Checkpoint 9.7 so...Ch. 9.3 - Look at the following declaration: String cafeName...Ch. 9.3 - Prob. 9.10CP
Ch. 9.3 - Prob. 9.11CPCh. 9.3 - Prob. 9.12CPCh. 9.3 - Prob. 9.13CPCh. 9.3 - Look at the following code: String str1 = To be,...Ch. 9.3 - Prob. 9.15CPCh. 9.3 - Assume that a program has the following...Ch. 9.4 - Prob. 9.17CPCh. 9.4 - Prob. 9.18CPCh. 9.4 - Prob. 9.19CPCh. 9.4 - Prob. 9.20CPCh. 9.4 - Prob. 9.21CPCh. 9.4 - Prob. 9.22CPCh. 9.4 - Prob. 9.23CPCh. 9.4 - Prob. 9.24CPCh. 9.5 - Prob. 9.25CPCh. 9.5 - Prob. 9.26CPCh. 9.5 - Look at the following string:...Ch. 9.5 - Prob. 9.28CPCh. 9.6 - Write a statement that converts the following...Ch. 9.6 - Prob. 9.30CPCh. 9.6 - Prob. 9.31CPCh. 9 - The isDigit, isLetter, and isLetterOrDigit methods...Ch. 9 - Prob. 2MCCh. 9 - The startsWith, endsWith, and regionMatches...Ch. 9 - The indexOf and lastIndexOf methods are members of...Ch. 9 - Prob. 5MCCh. 9 - Prob. 6MCCh. 9 - Prob. 7MCCh. 9 - Prob. 8MCCh. 9 - Prob. 9MCCh. 9 - Prob. 10MCCh. 9 - To delete a specific character in a StringBuilder...Ch. 9 - Prob. 12MCCh. 9 - Prob. 13MCCh. 9 - These static final variables are members of the...Ch. 9 - Prob. 15TFCh. 9 - Prob. 16TFCh. 9 - True or False: If toLowerCase methods argument is...Ch. 9 - True or False: The startsWith and endsWith methods...Ch. 9 - True or False: There are two versions of the...Ch. 9 - Prob. 20TFCh. 9 - Prob. 21TFCh. 9 - Prob. 22TFCh. 9 - Prob. 23TFCh. 9 - int number = 99; String str; // Convert number to...Ch. 9 - Prob. 2FTECh. 9 - Prob. 3FTECh. 9 - Prob. 4FTECh. 9 - The following if statement determines whether...Ch. 9 - Write a loop that counts the number of space...Ch. 9 - Prob. 3AWCh. 9 - Prob. 4AWCh. 9 - Prob. 5AWCh. 9 - Modify the method you wrote for Algorithm...Ch. 9 - Prob. 7AWCh. 9 - Look at the following string:...Ch. 9 - Assume that d is a double variable. Write an if...Ch. 9 - Write code that displays the contents of the int...Ch. 9 - Prob. 1SACh. 9 - Prob. 2SACh. 9 - Prob. 3SACh. 9 - How can you determine the minimum and maximum...Ch. 9 - Prob. 1PCCh. 9 - Prob. 2PCCh. 9 - Prob. 3PCCh. 9 - Prob. 4PCCh. 9 - Prob. 5PCCh. 9 - Prob. 6PCCh. 9 - Check Writer Write a program that displays a...Ch. 9 - Prob. 8PCCh. 9 - Prob. 9PCCh. 9 - Word Counter Write a program that asks the user...Ch. 9 - Sales Analysis The file SalesData.txt, in this...Ch. 9 - Prob. 12PCCh. 9 - Alphabetic Telephone Number Translator Many...Ch. 9 - Word Separator Write a program that accepts as...Ch. 9 - Pig Latin Write a program that reads a sentence as...Ch. 9 - Prob. 16PCCh. 9 - Lottery Statistics To play the PowerBall lottery,...Ch. 9 - Gas Prices In the student sample program files for...
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- True or FalseWhen you call a string object’s Split method, the method divides the string into two substrings and returns them as an array of strings.arrow_forwardAlternate Character DisplayWrite a method that accepts a String object as an argument and then returns the alternate characters as substring starting from index 0. For instance, if the string argument passed is “GREAT”, the method should return “GET”. Demonstrate the method in a program that asks the user to input a string and then passes it to the method.arrow_forwardWrite a single statement which creates a new StringBuffer object and sets its capacity to 50.arrow_forward
- By using one of the string objects, you will have the ability to precisely locate the place of the substring in which you are interested.arrow_forwardWhen the Split method of a string object is called with null as one of its arguments, what kind of characters are used as the delimiters?arrow_forwardlanguage using - Javaarrow_forward
- Analyze the code and then correct it.Dim strCity as String = "Miami"Dim strState as Double = "Florida"Dim strLocation as StringstrLoc = strCity + strStatearrow_forwardYou may utilise one of the of a string object to find out where the substring is located.arrow_forwardlength should be a multiple of 8, if the string is not a multiple of 8 you should remove the numbers in excess. Examples textToNumberBinary("zero textToNumberBinary("Zero textToNumberBinary("zero one zero one zero one zero one") → "01010101" one zero ONE zero one zero one") → "01010101" one zero one zero one zero one one two") → "01010101"arrow_forward
- Lab Goal : This lab was designed to teach you how to use a while loop. Lab Description (JAVA PROGRAMMING): Remove all occurrences of the removal string from the original string. Each time you take out the removal string you must also remove the letter that preceded the removal string. After you remove a string and its leading character, you must check to see if any more occurrences of the removal string exist. Sample Data : xR-MxR-MHelloxR-M R-M sxsssxssxsxssexssxsesss xs fuxqwexqwertyxqwexqwe Sample Output : xR-MxR-MHelloxR-M - String to remove R-M Hello sxsssxssxsxssexssxsesss - String to remove xs sesss fuxqwexqwertyxqwexqwertyrtyxqwertyrtyn - String to remove qwerty fun dogdogcatddodogdogdoggog - String to remove dog catgog algorithm help use indexOf to look for more removals while you have more removals { take out the current removal using substring use indexOf to look for more removals } I need help with assignment: "String Cleaner" StringRemover.js: //(c) A+…arrow_forwardButton Toggle How can we make a button that toggles a text view (not the button label) between "Howdy Class!" and "You Pressed Me!"? Please write the java onClick function that would be specified in the button onClick property. Do not use string comparison to determine the current state. Also, do not use hard code string values.arrow_forwardUtilizing an instance of a string object may help you locate the substring.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT