Java program to print vowels in a String

In this post, we will see how to print and count vowels in a string.

Print Vowels in a String

If any character in String satisfy below condition then it is vowel and we will add it to Hashset.

character==’a’ || character==’A’ || character==’e’ || character==’E’ ||
character==’i’ || character==’I’ || character==’o’ || character==’O’ ||
character==’u’ || character==’U’

Output:

💻 Awesome Tech Resources:
  • Looking for ⚒️ tech jobs? Go to our job portal.
  • Looking for tech events? Go to tech events 🗓️ Calendar.️
Enter an String : Java2blog
Vowels are:
a o

Explanation

  1. Iterate over String str and check each Character is vowel or not based on below condition
  2. If it is vowel, then print the vowel

Count number of Vowels in the String

Here is the program to count number of Vowels in the String.

Output:

Enter an String : Java2blog
Number of vowels: 3

Explanation

  1. Declare count variable and initialize it with 0.
  2. Iterate over String str and check each Character is vowel or not based on below condition
  3. If it is vowel, then increment the count
  4. Once loop is complete, then return the count.

That’s all about how to print vowels in a string in java.


import_contacts

You may also like:

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

Subscribe to our newletter

Get quality tutorials to your inbox. Subscribe now.