- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java program to count the number of vowels in a given sentence
To count the number of vowels in a given sentence:
- Read a sentence from the user
- Create a variable (count) initialize it with 0;
- Compare each character in the sentence with the characters {'a', 'e', 'i', 'o', 'u' }
- If a match occurs increment the count.
- Finally print count.
Example
import java.util.Scanner; public class CountingVowels { public static void main(String args[]){ int count = 0; System.out.println("Enter a sentence :"); Scanner sc = new Scanner(System.in); String sentence = sc.nextLine(); for (int i=0 ; i<sentence.length(); i++){ char ch = sentence.charAt(i); if(ch == 'a'|| ch == 'e'|| ch == 'i' ||ch == 'o' ||ch == 'u'||ch == ' '){ count ++; } } System.out.println("Number of vowels in the given sentence is "+count); } }
Output
Enter a sentence : Hi how are you welcome to tutorialspoint Number of vowels in the given sentence is 22
- Related Articles
- Java Program to Count the Number of Vowels and Consonants in a Sentence
- Swift Program to Count the Number of Vowels and Consonants in a Sentence
- Kotlin Program to Count the Number of Vowels and Consonants in a Sentence
- Haskell Program to Count the Number of Vowels and Consonants in a Sentence
- Java program to count the number of consonants in a given sentence
- How to Count the Number of Vowels and Consonants in a Sentence in Golang?
- Python program to count the number of vowels using set in a given string
- Python program to count the number of vowels using sets in a given string
- Python program to count number of vowels using set in a given string
- Java program to count the characters in each word in a given sentence
- Java Program to count vowels in a string
- Java Program to count all vowels in a string
- C# Program to count number of Vowels and Consonants in a string
- Java program to Count the number of digits in a given integer
- Count the number of vowels occurring in all the substrings of given string in C++

Advertisements