Respuesta :
The program is an illustration of methods
What are methods?
A Method in java is a block of named statements, that can be executed by simply calling it.
The longestStreak method
The method longestStreak in Java is as follows where comments are used to explain each line is as follows:
public static void longestStreak(String str){
//This initializes the initial character to an empty character
char previousChar = ' ';
//This initializes the current and the longest streak to an empty string
String largestStreak = "", currentStreak = "";
//This iterates through the string
for (int i = 0; i < str.length(); i++){
//This checks if the current character and the previous character are not the same
if (str.charAt(i) != previousChar){
//If yes, the streak is reset
currentStreak = "";
}
//The streak continues here
currentStreak += str.charAt(i);
//This checks the length of the longest streak
if (currentStreak.length() > largestStreak.length()){
largestStreak = currentStreak;
}
//This sets the previous character to the current character
previousChar = str.charAt(i);
}
//This prints the longest streak and its length
System.out.println(largestStreak.charAt(0)+" "+largestStreak.length());
}
Read more about similar programs at:
https://brainly.com/question/19360184