Skip to content

Instantly share code, notes, and snippets.

@muthugit
Last active April 15, 2017 19:17
Show Gist options
  • Save muthugit/ad8e4636b6e499bc49365d0b5a84b712 to your computer and use it in GitHub Desktop.
Save muthugit/ad8e4636b6e499bc49365d0b5a84b712 to your computer and use it in GitHub Desktop.
public class consecutiveChars{
public static void main(String[] args) {
String inputString = "11000011111";
int count = 1, maxCount = 0, iteration = 0;
char maxChar = 0;
for (char currentChar : inputString.toCharArray()) {
if (++iteration < inputString.toCharArray().length && currentChar == inputString.toCharArray()[iteration]) {
count++;
} else {
if (count >= maxCount) {
maxCount = count;
maxChar = inputString.toCharArray()[iteration - 1];
}
count = 1;
}
}
System.out.println(maxCount);
System.out.println(maxChar);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment