Answered step by step
Verified Expert Solution
Question
1 Approved Answer
/ * Given a string, return true if it ends in ly . endsLy ( oddly ) - > true endsLy
Given a string, return true if it ends in ly
endsLyoddly true
endsLyy false
endsLyoddy false
public boolean endsLyString str
return false;
Given a string and an int n return a string made of the first and last n chars from the string. The
string length will be at least n
nTwiceHello "Helo"
nTwiceChocolate "Choate"
nTwiceChocolateCe
public String nTwiceString str int n
return null;
Given a string and an int n return a string that starts at n and has a length of Note that n may or may not be a valid
location in the string. If n is too low or too high to define a string of length return the string's first characters.
The string length will be at least
twoCharjavaja
twoCharjavava
twoCharjavaja
public String twoCharString str int n
return null;
Given a string of odd length, return the string length from its middle, so "Candy" yields "and".
The string length will be at least
middleThreeCandy "and"
middleThreeand "and"
middleThreesolving "lvi"
public String middleThreeString str
return null;
Given a string, return true if "bad" appears starting at index or in the string, such as with
"badxxx" or "xbadxx" but not "xxbadxx". The string may be any length, including Note: use equals
to compare strings.
hasBadbadxx true
hasBadxbadxx true
hasBadxxbadxx false
public boolean hasBadString str
return false;
Given a string and a nonnegative int n return a larger string that is n copies of the original string.
stringTimesHi "HiHi"
stringTimesHi "HiHiHi"
stringTimesHiHi
public String stringTimesString str int n
return null;
Given a string and a nonnegative int n we'll say that the front of the string is the first chars, or
whatever is there if the string is less than length Return n copies of the front;
frontTimesChocolate "ChoCho"
frontTimesChocolate "ChoChoCho"
frontTimesAbc "AbcAbcAbc"
public String frontTimesString str int n
return null;
Count the number of xx in the given string. We'll say that overlapping is allowed, so xxx contains xx
countXXabcxx
countXXxxx
countXXxxxx
public int countXXString str
return ;
Given a string, return true if the first instance of x in the string is immediately followed by another x
doubleXaxxbb true
doubleXaxaxax false
doubleXxxxxx true
public boolean doubleXString str
return false;
Given a string, return a new string made of every other char starting with the first, so "Hello" yields "Hlo".
stringBitsHello "Hlo"
stringBitsHiH
stringBitsHeeololeo "Hello"
public String stringBitsString str
return null;
Given a nonempty string like "Code" return a string like "CCoCodCode".
stringSplosionCode "CCoCodCode"
stringSplosionabc "aababc"
stringSplosionab "aab"
public String stringSplosionString str
return null;
Given a string, return the count of the number of times that a substring length appears in the string and
also as the last chars of the string.
We don't count the end subString, so "hixxxhi" yields but the subString may overlap a prior position by one.
For instance, xxxx has a count of : one pair at position and the second at position The third pair at
position is the end subString, which we don't count.
lasthixxhi
lastxaxxaxaxx
lastaxxxaaxx
lastxxxx
public int lastString str
return ;
Given a string, return a version where all the x have been removed. Except an x at the very start or end
should not be removed.
stringXxxHxix "xHix"
stringXabxxxcd "abcd"
stringXxabxxxcdx "xabcdx"
public String stringXString str
return null;
Given a string, return a string made of the chars at indexes so "kittens" yields "kien".
altPairskitten "kien"
altPairsChocolate "Chole"
altPairsCodingHorror "Congrr"
public String altPairsString str
return null;
Suppose the string "yak" is unlucky. Given a string, return a version where all the "yak" are removed.
The "yak" strings will not overlap.
stringYakyakpak "pak"
stringYakpakyak "pak"
stringYakyakyaya
public String stringYakString str
return null;
java
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started