Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
4th Edition
ISBN: 9780134787961
Author: Tony Gaddis, Godfrey Muganda
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 9.4, Problem 9.18CP
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
java
Given a String str, find and print the shortest words. The String will have multiple words separated by commas and spaces. If there is words that have the same length, they should all be displayed at the end. Print all the shortest words in the following format:
Input: word1, word2, word3, word4, etc...
Output: [short1, short2, short3, etc...]
Hint: Think about what comes between each word in the sentence
Main topics: arrays, String, loops, if statements, primitive datatypes, operators
Example:
Input:
olive, fish, pursuit, old, warning, python, java, coffee, cat, ray
Output:
[old, cat, ray]
Scanner scan = new Scanner(System.in); String str = scan.nextLine();
COMPARING THE EFFICIENCY OF THE STRING AND STRINGBUILDER CLASSES
List the methods you'd need to figure out each of the following facts about a string object's value: includes the word "VIDI" as a substring
Chapter 9 Solutions
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
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
- Write an application that reads a five-letter word from the user and produces every possible three-letter string that can be derived from the letters of that word. For example, the three-letter words produced from the word “bathe” include “ate,” “bat,” “bet,” “tab,” “hat,” “the” and “tea.”arrow_forwardWhat is Modifying StringBuffer Objects?arrow_forwardUsing C# Language and Visual Studio.Create a guessing game that shows hint everytime you guess the correct letter using ArrayList and StringBuilder.arrow_forward
- Language: Java Write a program that reads a sentence from the keyboard. Depending on the last character of the sentence, print the message identifying the sentence as declarative (ends with a period), interrogative (ends with a question mark), exclamatory (end with an exclamation point), or other. Hint: you can use charAt() method from the String class to extract the last character of the input line. The character of a String str is at str.length()-1 position. For taking a sentence as input use the nextLine() method from the Scanner class. You have to use if/else if selection. Sample input and output: Sample 1 Input: How are you? Output: Interrogative Sample 2 Input: I am good. Output: Declarative Sample 3 Input: That is amazing! Output: Exclamatory Sample 4 Input: Although, Output: Other Answer:arrow_forwardWrite in C language Description Write a program to determine if a string is apalindrome or not. Input Input string will include only letter,please consider uppercase and lowercase as the same. Output Please refer to the sample output. Sample Input 1 AbcBa Sample Output 1 AbcBa is a palindrome. Sample Input 2 AAaab Sample Output 2 AAaab is not a palindrome. Expert Answer (Output doesn't match Sample output) Step 1 #include <stdio.h>#include <string.h>int main(){ char string1[20]; int i, length; int flag = 0; printf("Enter a string:"); scanf("%s", string1); length = strlen(string1); for(i=0;i < length ;i++){ if(string1[i] != string1[length-i-1]){ flag = 1; break; }} if (flag) { printf("%s is not a palindrome", string1); } else { printf("%s is a palindrome", string1); } return 0;} Step 2 OUTPUT Enter a string : Wow Wow is a palindrome (saying not a palindrome) Press…arrow_forwardDetermine whether a string is a palindrome A palindrome is a string of characters that reads the same from right to left as it does from left to right, regardless of punctuation and spaces. Some famous English palindromes include the following “Madam, I’m Adam”, and “Never odd or even”. Of course, a simpler example would be the world “radar”.The specifications for this assignment are: Write and test a non-recursive solution in Java that determines whether a string is a palindrome •Your program should consist of at least two methods: (1) the main method (2) the method which performs the task of determining whether the specified string is a palindrome. You should name this method isPalindrome. You should name the class that contains your “main” method and the isPalindrome method FindPalindrome. •You must use a Stack and a Queue in your solution:Make sure to Write your own Stack and Queue based on the Vector in the Java API and use those in your solution. You should name those classes…arrow_forward
- I have to add this solution to a conversion code. This chapter is focused on strings and string manipulation, including slicing, searching, splitting, and case conversions. Can you help me with this? 1. Ask the user for their name and their email address before you display the results of the conversions. 2. When the user enters the email address search the string for the @ symbol. If the symbol is not found, ask the user to re-enter their email address till they get it right. 3. When you display the conversion output to the user, you must include the user’s name in the outputarrow_forwardUsing C# Language and Visual Studio.Create a guessing game that shows hint everytime you guess the correct letter using ArrayList and StringBuilder. FOR EXAMPLE THE WORD IS MATH IF THE PLAYER GUESS THE RIGHT LETTER SHOW THE RIGHT LETTER FOR EXAMPLE HE GUESSED THE RIGHT LETTER "A" THE OUTPUT MUST SHOW YOU GUESS THE CORRECT LETTER _A_ _arrow_forwarddef emotify(string): a=string.split() l=len(a) for i in range(0,l): if(a[i]=="smile"): a[i]=":)" if(a[i]=="grin"): a[i]=":D" if(a[i]=="sad"): a[i]=":((" if(a[i]=="mad"): a[i]=">:(" print (*a) string1=input("Enter the string:\n") emotify(string1); please explain this code. this is pythonarrow_forward
- No loopsarrow_forwardJAVA PROGRAMMING JAVA PROGRAMMING JAVA PROGRAMMINGarrow_forwardIs it the same? Tags: String Problem Description Puan Ruqayyah, Madam Chong and Miss Lela teach their dyslexia students to identify characters. They tested randomly on strings of characters and numbers. They found that a few children get excited when they read certain series of strings. The teachers were curious and began to find out that these kids love strings that have series of characters that can be read similarly from right and from left.There are not that many meaningful words and numbers with such pattern. The teachers are interested to collect these meaningful words and numbers to share with their dyslexia students. Examples of such strings are CIVIC, KAPAK, 2102012 (which is 2nd Oct 2012), 1102011 (which is 1st Oct 2011), among others.Now, you are to help Puan Ruqayyah and her colleagues to select such strings. Write a program that reads in a sequence of characters and determine if it can be read similarly from right and from left. InputThe first line of input is…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,