Decode a given string by removing duplicate occurrences | Java program for the above approach ; Function to count the appearances of each character ; If the character is lower case ; If the character is uppercase ; If the character is a punctuation mark ; Function to decode the given encoded String ; Iterate the given String str ; Find the index of the next character to be printed ; Driver Code
import java . util . * ; class GFG { static int findRepitition ( char a ) { if ( a <= ' z ' && a >= ' a ' ) { return a - ' a ' ; } else if ( a <= ' Z ' && a >= ' A ' ) { return a - ' A ' ; } return 0 ; } static void decodeString ( String str ) { String output = " " ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { output += ( str . charAt ( i ) ) ; i += findRepitition ( str . charAt ( i ) ) ; } System . out . print ( " Decrypted ▁ code ▁ is ▁ { " + output + " } " + "NEW_LINE"); } public static void main ( String [ ] args ) { String str = " abbbb ▁ acccdddd " ; decodeString ( str ) ; } }