Last active
April 15, 2017 19:17
-
-
Save muthugit/ad8e4636b6e499bc49365d0b5a84b712 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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