Count all Vowels in a String Java with Source Code

Count all Vowels in a String Java – To check whether all vowels are present or not in the string, create a Boolean Array as the hash data structure.

Iterate over the string character by character, marking each vowel present in the Boolean Array if the character is a vowel.

We have included a downloadable zip file in Java at the end of the program so that you may run the following codes.

Example Program

package count_all_vowels_in_string;

import java.util.Scanner;

public class Count_all_Vowels_in_String {

 
    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:

//Count all Vowels in a String Java: Sample Code Output

Enter a sentence :
earth
Number of vowels in the given sentence is 2

What is the importance of Counting the number of vowels in a string in Java?

Strings are unique in Java because the content of the string cannot be modified or overridden once it is created.

Strings can be used for a variety of purposes, and programmers can tailor them to their own needs.

How to count vowels in a string in Java?

How to count vowels in a string

STEP 1: BEGIN.
SET vCount = 0 and cCount = 0.
STEP 3: DEFINE string str = “This is a really straightforward statement.”
CONVERT str to lowercase in STEP 4.
STEP 5: MAKE I = 0
STEP 6: REPEAT STEPS 6–8 UNTIL istr.length is reached ()
7: If any of str’s characters matches a vowel, then. …
STEP 9: I = I + 1.

About the Project

The Count All Vowels in a String program below covers all of the necessary and vital elements that can be used for college projects by first-year, second-year, and final-year IT students.

The project is entirely written in Java and built in the NetBeans code editor.

Project Details and Technology

Project Name:Count all Vowels in a String Java with Source Code
AbstractCount all Vowels in a String Java – As we all know, vowels are ‘a’, ‘e’, I ‘o’, and ‘u,’ whereas consonants are ‘b’, ‘c’, ‘d’, ‘f’, and so on. Input: char = ‘r’ Output: Vowel Input: char = ‘e’ Output: Consonant In the following implementation, we’ll see if the given character matches one of the five vowels.
Language/s Used:Java
Java version (Recommended):8
Database:N/A
Type:Desktop Application
Developer:sourcecodehero
Updates:0

To start executing this project, make sure that you have  NetBeans IDE or any platform code editor installed on your computer.

How to count vowels in a string in Java: Follow the steps below

Time needed: 3 minutes

  • Step 1: Download Source Code

    To get started, find the downloaded source code file below and click to start downloading it.

    Count all Vowels in a String Java

  • Step 2: Extract File

    Navigate to the file’s location when you’ve finished downloading it and right-click it to extract it.

  • Step 3: Run the project

    Next, open NetBeans IDE click open project, and choose your download.

    Count all Vowels in a String Java open projects

  • Step 4: Run the project.

    Next, right-click the project folder and click run.

    Count all Vowels in a String Java run

Download the Source Code below

Summary

For those Web developers interested in learning more about web apps, this system is a fully functional project.

Inquiries

If you have any questions or comments on the project, please leave a comment below.

Leave a Comment