Created
November 9, 2021 15:20
-
-
Save codetricity/790c39261a8f33ed2cabe90fdb4c99aa to your computer and use it in GitHub Desktop.
example of finding matches in a string
This file contains hidden or 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 Main { | |
public static void main(String[] args) { | |
String data = "CCAAAAATTT!"; | |
char maxLetter = data.charAt(0); | |
int maxCount = 1; | |
for (int i = 0; i < data.length() -1; i++) { | |
int currentCount = 1; | |
char letter = data.charAt(i); | |
while (letter == data.charAt(i + 1)) { | |
currentCount++; | |
i++; | |
// System.out.println("found match: " + letter + " = " + currentCount); | |
if (currentCount > maxCount) { | |
maxCount = currentCount; | |
maxLetter = data.charAt(i); | |
} | |
System.out.println(i); | |
} | |
// System.out.println("max count is " + maxCount); | |
// System.out.println("max letter is " + maxLetter); | |
} | |
System.out.println(maxLetter + " " + maxCount); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment