Java Program to Count Vowels and Consonants in a String

Java Program to Count Vowels and Consonants in a String. The nucleus of a spoken word is a vowel, which is a speaking sound made with your mouth fairly open. A consonant is a sound produced by closing your mouth slightly. The majority of syllables have a vowel, while vowel-like consonants can also be syllables in the java program.

Java Program to Count Vowels and Consonants in a String

Definitions are simple phonologically: a vowel is any sound that does not make audible noise due to restriction in the vocal tract, and a consonant is any sound that does produce audible noise due to constriction. This approach, on the other hand, forces us to classify as vowels many sounds that function as consonants in speech. This is sample program to execute the C Program to Find Vowels in a String.

Vowels and Consonant in Java Program

The distinction between vowels and consonants is that a vowel is a speech sound that is created in the vocal tract without restriction. A consonant, on the other hand, is a speaking sound generated with a limitation in the vocal tract. It’s worth noting that vowels can relate to both vowel sounds and alphabet letters.

Pre Increment in Java

The value is first increased and then used inside the expression in the Pre-Increment. Syntax: a = ++x; If the value of ‘x’ is 10, then the value of ‘a’ will be 11. This is because the value of ‘x’ is updated before it is used in the expression.

Since you’re not using i++ or I as part of a larger statement, they’re identical. i++ and I are both abbreviations for I = I + 1.

Conditional Statement in Java

Decision Making in Java facilitates the creation of decision-driven statements and the execution of a specific set of code in response to specified situations. When the condition is false, we can combine the else statement with the if statement to execute a block of code.

The conditional statements in Java are as follows: If a particular condition is true, use if to specify a block of code to be run. If the same condition is false, use otherwise to specify a block of code to run. If the initial condition is false, use else if to define a new condition to test. C Program to Find Vowels in a String this program we will learn how to execute the code in to find the vowel strings in java.

class Main
{

public static void main(String[] args)
{
String line = "Inlarn 4 You";
int vowels = 0, consonants = 0, digits = 0, spaces = 0;
line = line.toLowerCase();
for (int i = 0; i < line.length(); ++i)
{
char ch = line.charAt(i);
if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u')
{
++vowels;
}
else if ((ch >= 'a' && ch <= 'z'))
{
++consonants;
}
else if (ch >= '0' && ch <= '9')
{
++digits;
}
else if (ch == ' ')
{
++spaces;
}
}
System.out.println("Vowels: " + vowels);
System.out.println("Consonants: " + consonants);
System.out.println("Digits: " + digits);
System.out.println("White spaces: " + spaces);
}
}

Output:

Vowels: 4
Consonants: 5
Digits: 1
White spaces: 2