From the course: Nail Your Java Interview

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Solution: Counting characters with string manipulation

Solution: Counting characters with string manipulation - Java Tutorial

From the course: Nail Your Java Interview

Start my 1-month free trial

Solution: Counting characters with string manipulation

(upbeat music) - [Instructor] Lets look at some functions that find the number of vowels and number of consonants in a given string. There are many different ways to solve this problem, but we'll walk through two different solutions. First, we set up our main function with the appropriate test input and call two different functions with each input. Let's take a look at the first implementation of the function. Here, we have our input string and create two invariables called vowels count and consonants count to keep track of how many vowels and consonants we found. Then we have a string to keep track of what we consider as vowels. Next, we normalize our input by converting it to lowercase and trimming off the extra whitespace. We also convert it to a char ray to keep our for-loop cleaner. Unfortunately, you can't use a for-each loop with strings. Getting into our for-loop, we iterate through the char array. We see…

Contents