Vowel Count using Java
Java Programming Language String in java (Article) String in java (Program)
20
Given Input:
Enter a String: Hello
Expected Output:
Here is your vowel count: 2
Program:
import java.util.*;
class VowelCount{
public static void main(String args[]){
String userString;
int loopVariable, vowelCount = 0, lengthOfString;
Scanner sc = new Scanner(System.in);
System.out.print("Enter a String: ");
userString = sc.nextLine();
lengthOfString = userString.length();
for(loopVariable = 0; loopVariable < lengthOfString; loopVariable++)
{
char presentCharacter = userString.charAt(loopVariable);
if( presentCharacter == 'a' || presentCharacter == 'e' || presentCharacter == 'i' ||
presentCharacter == 'o' || presentCharacter == 'u' || presentCharacter == 'A' || presentCharacter == 'E'||
presentCharacter == 'I' || presentCharacter == 'O' || presentCharacter == 'U'){
vowelCount = vowelCount + 1;
}
}
System.out.println("Here is your vowel count: "+vowelCount);
}
}
Output:
Enter a String: Hello
Here is your vowel count: 2
Press any key to continue . . .
This Particular section is dedicated to Programs only. If you want learn more about Java Programming Language. Then you can visit below links to get more depth on this subject.
Here is your vowel count: 2
Program:
import java.util.*; class VowelCount{ public static void main(String args[]){ String userString; int loopVariable, vowelCount = 0, lengthOfString; Scanner sc = new Scanner(System.in); System.out.print("Enter a String: "); userString = sc.nextLine(); lengthOfString = userString.length(); for(loopVariable = 0; loopVariable < lengthOfString; loopVariable++) { char presentCharacter = userString.charAt(loopVariable); if( presentCharacter == 'a' || presentCharacter == 'e' || presentCharacter == 'i' || presentCharacter == 'o' || presentCharacter == 'u' || presentCharacter == 'A' || presentCharacter == 'E'|| presentCharacter == 'I' || presentCharacter == 'O' || presentCharacter == 'U'){ vowelCount = vowelCount + 1; } } System.out.println("Here is your vowel count: "+vowelCount); } }
Output:
Enter a String: Hello Here is your vowel count: 2 Press any key to continue . . .
This Particular section is dedicated to Programs only. If you want learn more about Java Programming Language. Then you can visit below links to get more depth on this subject.