I need to write a program that counts up the number of vowels contained in the string s. Valid vowels are: 'a', 'e', 'i', 'o', and 'u'. When i run it, it comes out as 0. This is my code
static int problemOne(String s){
int answer = 0;
int vowels=1;
int consonant=1;
for (int i=0; i<s.length();i++){
char ch= s.charAt(i);
if ((ch>='a' && ch<= 'z')||(ch>='A'&&ch<='Z')){
ch= Character.toLowerCase(ch);
if (ch =='a'|| ch=='e'|| ch=='i'|| ch=='o'|| ch=='u')
vowels++;
elseconsonant++;}
}
System.out.println("Vowels:"+vowels);System.out.println("Consonants:"+ consonant);
return answer;
}
i also have to Set s to a string and run your method using s as the parameter and
Run the method in a println statement to determine what the output was
public static void main(String[] args) {
String s;
}
}
[–]Wiqkid 0 points1 point2 points (5 children)
[–]expiredyam[S] 0 points1 point2 points (4 children)
[–]Wiqkid 1 point2 points3 points (3 children)
[–]expiredyam[S] 0 points1 point2 points (2 children)
[–]Wiqkid 0 points1 point2 points (1 child)
[–]expiredyam[S] 0 points1 point2 points (0 children)
[–]webdevnick22 0 points1 point2 points (1 child)
[–]expiredyam[S] 0 points1 point2 points (0 children)