Java program to count the number of vowels in a String
Login/Signup to comment
15 comments on “Java program to count the number of vowels in a String”
×


30+ Companies are Hiring
Get Hiring Updates right in your inbox from PrepInsta
Login/Signup to comment
Get Hiring Updates right in your inbox from PrepInsta
public class Noofvowels {
public static void main(String arg[]) {
String s = “Lalit”;
int count = 0;
for(int i=0;i<s.length();i++) {
char c= s.charAt(i);
c=Character.toUpperCase(c);
if(c=='A'||c=='E'||c=='I'||c=='O'||c=='U') {
count++;
}
}
System.out.println(count);
}
}
Hey there, Thanks for commenting, kindly join our Discord server, our mentors will guide you further precisely will all your queries.🙌
import java.util.Scanner;
class HelloWorld1 {
public static void main(String[] args) {
// MeGhAnA
// mEgHaNa
Scanner sc=new Scanner(System.in);
String str=sc.next();//apple
char[] ch =str.toCharArray();
int count=0;
for(int j=0;j<str.length();j++){
if(isVowel(ch[j])){
count++;
}
}
System.out.println(count);
}
public static boolean isVowel(char ch){
return (ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u'||ch=='A'||ch=='E'||ch=='I'||ch=='O'||ch=='U');
}
}