Answer:
public static int count_vowels(String str){
String word = str.replaceAll("[^a-zA-Z0-9]", "");
String text = word.toUpperCase();
int lenOfString = text.length();
int count =0;
for(int i =0; i<lenOfString; i++){
if(text.charAt(i)=='A'||text.charAt(i)=='E'||text.charAt(i)=='I'
||text.charAt(i)=='O'||text.charAt(i)=='U'){
count++;
}
}
return count;
}
Explanation:
This has been implemented using Java programming language.
Firstly, white spaces, special characters and punctions are removed from the string uisng the replaceAll() method
The string is converted to all upper cases
a for loop is used to count the number of vowels and store to a variable count
In the main method a call to count_vowels is done
<em>public class num1 {</em>
<em> public static void main(String[] args) {</em>
<em> String name = "David %$ !. gjak";</em>
<em> System.out.println("The number of vowels in "+name+ " are "+count_vowels(name));</em>
<em> }</em>
<em> public static int count_vowels(String str){</em>
<em> String word = str.replaceAll("[^a-zA-Z0-9]", "");</em>
<em> String text = word.toUpperCase();</em>
<em> int lenOfString = text.length();</em>
<em> int count =0;</em>
<em> for(int i =0; i<lenOfString; i++){</em>
<em> if(text.charAt(i)=='A'||text.charAt(i)=='E'||text.charAt(i)=='I'</em>
<em> ||text.charAt(i)=='O'||text.charAt(i)=='U'){</em>
<em> count++;</em>
<em> }</em>
<em> }</em>
<em> return count;</em>
<em> }</em>
<em>}</em>
<em />
The complete program with a Main method is given below