Question: Write a program in Java (LoopPlay.java) that prompts the user for two strings, userStr1 and userStr2, and then performs all of the following tasks: 1.Prints
Write a program in Java (LoopPlay.java) that prompts the user for two strings, userStr1 and userStr2, and then performs all of the following tasks:
1.Prints the number of times that the first letter in your first name appears anywhere in userStr1.
2.Prints "POP!" if the userStr1 contains a string in the pattern "p*p", where the middle char '*' can be any char. Prints "NOT!" if the pattern is not found.
3.Prints the number of times the userStr2 contains a string in the pattern "m*m", where the middle char '*' can be any char.
4. Print the string made of the first char of userStr1, then the first char of userStr2, then the second char of userStr1, then the second char of userStr2, and so on. Any leftover chars go at the end of the resulting string.
5. Print the string that is between the first and last appearance of "bread" in userStr2, or print "Not a sandwich!" if there are not two occurrences of "bread".
6. Prints "Found one in the middle." if "one" appears right in the middle of userStr2, otherwise print "No one in the middle.".
To be considered in the middle, the number of chars to the left and right of the "one" must differ by at most one.
Goal is to traverse strings using loops. Some sample outputs below for clarification if steps are confusing.

-jGRASP exec: java LoopPlay Please enter the first sentence: I would like to ski Please enter the second sentence: Mom, may I go play? Mmmm 1. The number of times the letter 'I'appears is: 3 2. NOT 3. The number of times the pattern "m*m" appears is: 3 4. The mixed string is: IM owmo, u lmda yl iIk eg ot op lsakyi? Mmmm 5. Not a sandwich! 6. No one in the middle -jGRASP: operation complete Please enter the first sentence: Pop goes the paper pa Please enter the second sentence: Memes bread and one maam 1. The number of times the letter I' appears is: 0 2. POP! 3. The number of times the pattern "m*m" appears is: 1 4. The mixed string is: PMoepm egso ebsr etahde apnadp eorn ep amaam 5. Not a sandwich! 6. No one in the middle. -jGRASP exec: java LoopPlay Please enter the first sentence: abcdefg Please enter the second sentence: hijk 1. The number of times the letter 'I' appears is: 0 2. NOT 3. The number of times the pattern "m*m" appears is:0 4. The mixed string is: ahbicjdkefg 5. Not a sandwich! 6. No one in the middle
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
