Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import static java.lang.Math.*;
- import static java.lang.System.*;
- public class test {
- public static void main (String[] args) {
- String str = "CCAAAAATTT!";
- int counter1 = 0, counter2 = 0;
- char firstChar = 0, secondChar = 0;
- for (int i = 0; i < str.length(); i++) {
- if (i + 2 > str.length()) {
- if (str.charAt(i) == str.charAt(i-1)) {
- counter1++;
- firstChar = str.charAt(i);
- }
- }
- else if ((str.charAt(i) == str.charAt(i + 1)) || str.charAt(i) == str.charAt(i - 1)) {
- counter1++;
- firstChar = str.charAt(i);
- }
- if (counter1 > counter2) {
- counter2 = counter1;
- counter1 = 0;
- secondChar = firstChar;
- firstChar = 0;
- }
- }
- System.out.println(secondChar + " " + counter2);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement