Advertisement
Guest User

Untitled

a guest
Mar 29th, 2020
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.61 KB | None | 0 0
  1.     public static void main(String[] args) {
  2.         int count = 0;
  3.         int currentComprimation = -1;
  4.         String s ="aabbbccccc";
  5.  
  6.         for (int i =  0; i < s.length(); i++) {
  7.             if(currentComprimation == s.charAt(i)) {
  8.                 count++;
  9.             } else {
  10.                 if(currentComprimation != -1) {
  11.                     System.out.print((char) currentComprimation + "" + count);
  12.                 }
  13.                 count = 1;
  14.                 currentComprimation = s.charAt(i);
  15.             }
  16.         }
  17.         System.out.print((char)currentComprimation + "" + count);
  18.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement