Skip to content
Advertisement

Count the Characters in a String Recursively & treat “eu” as a Single Character

I am new to Java, and I’m trying to figure out how to count Characters in the given string and threat a combination of two characters "eu" as a single character, and still count all other characters as one character.

And I want to do that using recursion.

Consider the following example.

Input:

JavaScript

Desired output:

JavaScript

Current output:

JavaScript

I’ve been trying a lot and still can’t seem to figure out how to implement it correctly.

My code:

JavaScript

Advertisement

Answer

OP wants to count all characters in a string but adjacent characters “ae”, “oe”, “ue”, and “eu” should be considered a single character and counted only once.

Below code does that:

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement