Answers for "to find vowels in a string in java"

0

count vowels in java

import java.util.*;
class CountVowel
{
    public static void main(String args[])
    {
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter to count vowels: ");
        String input = sc.nextLine();
        String s = input.toLowerCase();
        int l = input.length();
        int c = 0;
        
        for(int i = 0; i <= l - 1; i++)
        {
            char d = s.charAt(i);
            if(d == 'a' || d == 'e' || d == 'i' || d == 'o' || d == 'u')
            {
                c++;
            }
        }
        System.out.println("Number of Vowels: " + c);
        sc.close();
    }
}
Posted by: Guest on March-15-2022
-1

check vowel present in string java

public class FindingVowels {
   public static void main(String args[]) {

      String str = new String("Hi Welcome to Tutorialspoint");
      for(int i=0; i<str.length(); i++) {
         if(str.charAt(i) == 'a'|| str.charAt(i) == 'e'|| str.charAt(i) == 'i' || str.charAt(i) == 'o' || str.charAt(i) == 'u') {
            System.out.println("Given string contains "+str.charAt(i)+" at the index "+i);
         }
      }
   }
}
Posted by: Guest on November-06-2021

Code answers related to "to find vowels in a string in java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language