Question: Consider the following program that counts consonants in a string: import java.io.*; class GFG { // Function to check for consonant static boolean isConsonant(char ch)

Consider the following program that counts consonants in a string:

import java.io.*; class GFG {

// Function to check for consonant static boolean isConsonant(char ch) {

 // To handle lower case ch = Character.toUpperCase(ch); 

return !(ch == 'A' || ch == 'E' || ch == 'I'|| ch == 'O'||

ch == 'U') && ch >= 65 && ch <= 90;

}

static int totalConsonants(String str) {

int count = 0; for (int i = 0; i < str.length(); i++)

// To check is character is Consonant if (isConsonant(str.charAt(i)))

++count; return count;

}

// Driver code public static void main(String args[]) {

 String str = "abc de"; 

System.out.println( totalConsonants(str)); }

}

Rewrite totalConsonants method in a recursive way.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!