Advertisement
apad464

FRQ code that doesn't work

Sep 28th, 2022
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.96 KB | None | 0 0
  1. import static java.lang.Math.*;
  2. import static java.lang.System.*;
  3.  
  4. public class test {
  5.     public static void main (String[] args) {
  6.         String str = "CCAAAAATTT!";
  7.         int counter1 = 0, counter2 = 0;
  8.         char firstChar = 0, secondChar = 0;
  9.  
  10.         for (int i = 0; i < str.length(); i++) {
  11.             if (i + 2 > str.length()) {
  12.                 if (str.charAt(i) == str.charAt(i-1)) {
  13.                     counter1++;
  14.                     firstChar = str.charAt(i);
  15.                 }
  16.             }
  17.             else if ((str.charAt(i) == str.charAt(i + 1)) || str.charAt(i) == str.charAt(i - 1)) {
  18.                 counter1++;
  19.                 firstChar = str.charAt(i);
  20.             }
  21.             if (counter1 > counter2) {
  22.                 counter2 = counter1;
  23.                 counter1 = 0;
  24.                 secondChar = firstChar;
  25.                 firstChar = 0;
  26.             }
  27.         }
  28.         System.out.println(secondChar + " " + counter2);
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement