Program to count the total number of vowels and consonants in a string.

 public class HelloWorld{


     public static void main(String []args){

        

        String file = "This is a really simple sentence";

        

        int count = 0;

        int count1 = 0;

        

        for(int i =0 ;i<file.length();i++){

            char v = file.charAt(i);

            if(v=='a' || v== 'e' || v=='i' || v=='o' || v=='u'){

               count++;

            }else

            {

                count1++;

            }

        }

        

         System.out.println("it is a vowels "+count);

         System.out.print("it is a consonants "+count1);

       

     }

}

Comments

Popular posts from this blog

Git and Github

bubble short Q1

Java Program to Check Whether the String Consists of Special Characters