C Program to Find Vowels in a String

How to Find Vowels in a String in Java. 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.

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

How to Find Vowels in a String in Java and How to Differentiate

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.

Difference Between Vowels and Consonant in Java

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.

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. How to find vowels in a string in Java this program we will learn how to execute the code in to find the vowel strings in java.

Similar Programs