find number of vowels in string java code example

Example 1: java find all of letter in string

String stringName = "Hello";
String characterToFind = "l";
//This example will find all the Ls in this string and will print the index of
//it as soon as it is detected

for(int i = 0; i < stringName.length(); i++){
  if(stringName.substring(i, i+1).equals(characterToFind)){
    System.out.println(characterToFind + "found at " + i);
  }
  
}

Example 2: output percentage of vowels and consonants in a given file in python

# Python Program to Count Vowels and Consonants in a String

str1 = input("Please Enter Your Own String : ")
vowels = 0
consonants = 0

for i in str1:
    if(i == 'a' or i == 'e' or i == 'i' or i == 'o' or i == 'u'
       or i == 'A' or i == 'E' or i == 'I' or i == 'O' or i == 'U'):
        vowels = vowels + 1
    else:
        consonants = consonants + 1
 
print("Total Number of Vowels in this String = ", vowels)
print("Total Number of Consonants in this String = ", consonants)