Java program to count the number of vowels in a String
Login/Signup to comment
14 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
import java.util.*;
class HelloWorld {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
String s=sc.nextLine();
int count=0;
for(int i=0;i<s.length();i++){
char c=s.charAt(i);
if(c == 'A' || c == 'E' || c == 'I' || c == '0' || c == 'U' || c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u'){
count++;
}
}
System.out.print(count);
}
}
import java.util.Scanner;
public class String2 {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
String s = sc.next();
char[] ch = s.toCharArray();
String v = “AEIOUaeiou”;
char [] vow = v.toCharArray();
int count = 0;
for(int i=0; i< ch.length; i++){
for(int j=0; j< vow.length; j++){
if(ch[i] == vow[j]){
count++;
}
}
}
System.out.println(count);
}
}
import java.util.*;
public class Main
{
public static void main (String[]args)
{
String str=”Gyanendra Tiwari”;
System.out.println(find(str));
}
public static int find(String str){
int count=0;
for(int i=0;i<str.length();i++){
char ch=Character.toLowerCase(str.charAt(i));
if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u'){
count++;
}
}
return count;
}
}
import java.util.Scanner;
public class Vowel {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
System.out.println(“Enter the String:”);
String s = sc.nextLine();
int count = 0;
for (int i = 0; i < s.length(); i++) {
char ch = s.charAt(i);
if (ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U' || ch == 'a' || ch == 'e' || ch == 'i'
|| ch == 'o' || ch == 'u') {
count++;
}
}
System.out.println("The number of vowels are in " + s + " is " + count);
}
}
public class Main
{
public static void main(String[] args) {
String s = “prepinsta”;
char[] c = s.toCharArray();
int vowel=0;
for (int i = 0; i < s.length(); i++) {
if(s.charAt(i)=='a' || s.charAt(i)=='e' || s.charAt(i)=='i' || s.charAt(i)=='o' || s.charAt(i)=='u')
vowel++;
}
System.out.println("Vowels: " + vowel);
}
}
import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
String str = sc.nextLine();
int count = 0;
for (int i = 0; i < str.length(); i++) {
char c = str.charAt(i);
if (c == 'A' || c == 'E' || c == 'I' || c == '0' || c == 'U' || c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') {
count++;
}
}
System.out.println(count);
}
}
public class Main
{
public static void main(String[] args) {
String str=”prepinsta”;
int count=0;
for(char ch: str.toCharArray()){
if(ch==’a’||ch==’e’||ch==’i’||ch==’o’||ch==’u’)
count++;
}
System.out.println(“Number of vowels= “+count);
}
}
import java.util.Scanner;
public class p3 {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
System.out.println(“Enter a String”);
String s1 = sc.nextLine();
int vowel = 0;
int consonant = 0;
for(int i = 0 ; i <s1.length() ; i ++){
if(s1.charAt(i) == 'a' ||s1.charAt(i) == 'e' ||s1.charAt(i) == 'i' ||s1.charAt(i) == 'o' ||s1.charAt(i) == 'u' ||s1.charAt(i) == 'A' ||s1.charAt(i) == 'E' ||s1.charAt(i) == 'I' ||s1.charAt(i) == 'O' ||s1.charAt(i) == 'U' ){
vowel ++;
}else{
consonant ++;
}
}
System.out.println(vowel + " vowels present");
System.out.println(consonant + "consonants present");
}
}
import java.util.*;
class Baba {
public static void main(String[] arfs) {
Scanner sc = new Scanner(System.in);
System.out.print(“Enter a String: “);
String s = sc.next();
int count = 0;
for(int i=0; i<s.length(); i++) {
char x = Character.toLowerCase(s.charAt(i));
if(x == 'a' || x == 'e'|| x== 'i'|| x=='o' || x=='u') {
count++;
}
}
System.out.println(count);
}
}
import java.util.Scanner;
public class vowelcount {
public static void main(String[] args) {
int c=0;
String vowel=”aeiouAEIOU”;
Scanner sc= new Scanner(System.in);
String s= sc.next();
for( int i=0;i< s.length();i++){
if( vowel.indexOf(s.charAt(i)) !=-1){
c++;
}
}
System.out.println(c);
}
}
package arrays;
class distinct {
public static void main(String[] args)
{
int count=0;
String str=”abhiaei”;
for(int i=0;i<str.length();i++) {
char ch = str.charAt(i);
if (ch=='a' || ch=='e' || ch=='i' || ch=='o'|| ch=='u') {
count++;
}
}
System.out.println("vovels " +count);
}
}
Thank you prepinsta for publishing my code…