Java Program to Print Vowels in a String - Source Code

In this tutorial, I will show you how to count the number of Vowels in a sentence using a Java Source code. JOptionPane used here to beautify the project, but you can get a console output as well.

Step 1: Create file in Eclipse (I used Eclipse as the Java IDE but you can use this file in any other Java IDEs as well)

//copyrighted by
import javax.swing.JOptionPane;

public class VowelCount{

    public static void main(String args[]){
        String sentence=JOptionPane.showInputDialog("Enter Sentence:");
        int count = 0;
        for (int i = 0; i < sentence.length(); i++) {
            char c = sentence.charAt(i);
            if (c=='a' || c=='e' || c=='i' || c=='o' || c=='u') {
        JOptionPane one = new JOptionPane();
        JOptionPane.showMessageDialog(one,"Vowel count is" + " " + count);

Step 2: Run the program


  1. Thanks for sharing a useful information with us. If someone wants to know about Safety Softwares and Occupational health and Safety Software I think this is the right place for you.


Post a Comment