Computer Science, asked by Srinitasingh768, 7 months ago

write a program in java to accept any sentence and display the number of vowels in different lines​

Answers

Answered by abhirvi002
0

Answer:

public class Count {

   public static void main(String[] args) {

       String line = "This website is aw3som3.";

       int vowels = 0, consonants = 0, digits = 0, spaces = 0;

       line = line.toLowerCase();

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

       {

           char ch = line.charAt(i);

           if(ch == 'a' || ch == 'e' || ch == 'i'

               || ch == 'o' || ch == 'u') {

               ++vowels;

           }

           else if((ch >= 'a'&& ch <= 'z')) {

               ++consonants;

           }

           else if( ch >= '0' && ch <= '9')

           {

               ++digits;

           }

           else if (ch ==' ')

           {

               ++spaces;

           }

       }

       System.out.println("Vowels: " + vowels);

       System.out.println("Consonants: " + consonants);

       System.out.println("Digits: " + digits);

       System.out.println("White spaces: " + spaces);

   }

}

Explanation:

Counts the Number of Vowels and Consonants in a Sentence

Similar questions