Fri Oct 22 2021
Count Vowel
Java Programming1312 views
File Name: vowel-count.java
import java.io.*;
import java.util.Scanner;
class count {
String txt;
count(String stn) {
this.txt = stn;
}
int vowel_count() {
int count = 0;
int length = 0;
while(length != txt.length()) {
/* Convert string to character */
if(vowel_count(txt.charAt(length)))
count++;
length++;
}
return count;
}
boolean vowel_count(char a) {
/* Convert character to lowercase */
a = Character.toLowerCase(a);
/* Checking for vowel */
if(a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u')
return true;
else
return false;
}
}
class vowelcount {
public static void main(String args[ ]) {
Scanner input = new Scanner(System.in);
System.out.println("Enter a String to count number of vowels:");
count vc = new count(input.nextLine());
System.out.println("There have "+vc.vowel_count()+" vowels.");
}
}
/* Output */
Enter a String to count number of vowels:
Hello World
There have 3 vowels.
Author:Geekboots