Question: We'll say that a triple in a string is a char appearing three times in a row. Define a method countTriple so it will turn

We'll say that a "triple" in a string is a char appearing three times in a row. Define a method countTriple so it will turn the index of the LAST triple occurrence; otherwise, return -1. For example
countTriple("abcUUUabUUUc") will return 8 since the (last triple) U starts at index 8
countTriple("xxabyyyyycd") will return 6 since the last triple y is at index 6
countTriple("a") will return -1 since no triple was found
countTriple("abbccb") will return -1 since no triple was found
Starter
public class Triple{
// First define countTriple(String s) to find whether a char appearing three times in a row in a given string s. It should turn the beginning index of the LAST triple; otherwise, return -1. Hint: use looping and chartAt(int) to get the character and compare.
// Then complete the main(...)
// use Scanner to get user input of a String
// invoke countTriple(), based on the result, display a message that says LAST triple x appeared at the index (replace x with the actual char, with the returned index that character could be retrieved) or a message that says No Triple
}//end of class
PLEASE DO THE FOLLOWING IN JAVA
 We'll say that a "triple" in a string is a char

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!