Java program to print vowels in a String

In Java, String is represented as an Object.

String characters are represented in Unicode encoding.

In the English language, there are five vowels a, e, i, o, and u.

In any string, vowels can be in small or in large letters.

Here using the Java program we will see how to find vowels in the given string.

Vowels program in java

Vowel program in java are discussed as follows

We created many programs to check and count vowels and consonants from String, StringBuffer, and from files.

Java program to print vowels in a String is as below

Java program to print vowels in a String

Steps to develop the program

  1. Take a String
  2. Create a loop to iterate each character of the string
  3. Inside loop check characters for vowel, both for upper and lower case
  4. If the character is a vowel then print its position and character
Java program to print vowels in a String
Fig: Java program to print vowels in a String

In the above program, we created for loop and it runs up to string length.

charAt() is used to access characters at specified index position.

The above program is simple we can make some improvements to it.

We are comparing both uppercase and lower case, we can convert complete string in lower case and compare it will reduce all uppercase comparison.

How to find vowels in a string in java

Java program to count number of vowels in a string from File

test.txt file is stored in d drive and file content is as below.

The Scanner class is used to read test.txt file.

Vowels program in java using switch case

Q: write a program to determine whether the input character is a vowel or consonant or not an alphabet

program to count the number of vowels and consonants in a given string in java

Character class contains method isAlphabetic.

This method is checking whether a number is an alphabet or not.

If the number is alphabet then match the character using for each loop with vowel characters stored in the array.

If matched then the character is vowel else consonant.

Java program to replace vowels in a string

Read More

  1. Duplicate Number between 1 to n numbers
  2. Sum of two numbers using command line arguments
  3. Program to reverse a string
  4. Prime number program in java using while loop
  5. Print vowels in a String
  6. Square Star Pattern