Answers for "java program to count the number of consonants in a word"

3

count the number of words in a string java

public static void main(String[] args)
    { 
        //return the number of words in a string 
        
       String example = "This is a good exercise"; 
       
       int length = example.split(" ").length;
       
       System.out.println("The string is " + length + " words long.");
        
        
    }
Posted by: Guest on June-04-2020
0

calculate the number of vowels and consonants in a string in java

for (int k = 0; k < text.length(); k++) {
    char c = text.charAt(k);
    if (c == 'a' || c == 'e' || c == 'i' || 
       c == 'o' || c == 'u') 
              owls += vowls
else
            consonts += consonts
}
System.out.println("Vowel count is " + vowls); 
System.out.println("Consonant count is: " + consonts);
Posted by: Guest on June-29-2021

Code answers related to "java program to count the number of consonants in a word"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language