GlobalLogic interview question

Java coding with occurrence of character