SHARE
TWEET

Untitled

a guest Nov 12th, 2019 77 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public static void main(String[] args) {
  2.         String incoming = "AABBBBCCDDDDDMMVG";
  3.         StringBuilder b = new StringBuilder();
  4.  
  5.         if (incoming == null || incoming.isEmpty()) {
  6.             return;
  7.         }
  8.  
  9.         char[] chars = incoming.toCharArray();
  10.         char prev = chars[0];
  11.         int counter = 1;
  12.  
  13.         for (int i = 1; i < chars.length; i++) {
  14.             char current = chars[i];
  15.             if (current != prev) {
  16.                 b.append(prev).append(counter);
  17.                 prev = current;
  18.                 counter = 1;
  19.             } else {
  20.                 counter++;
  21.             }
  22.         }
  23.         b.append(prev).append(counter);
  24.         System.out.println(b.toString());
  25.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top