Answers for "java code that display the vowel"

1

how to check whether a character is vowel in java

public class CodeGrepper {
    public static boolean isVowel(char letter) {
        String vowels = "aeouiAEOUI";
        return vowels.indexOf(letter) != -1; 
    }
    public static void main(String[] args) {
        System.out.println(isVowel('a')); // true
        System.out.println(isVowel('z')); // false
    }
}
Posted by: Guest on April-07-2022
-1

java program to print vowels in a string

String str = "hello";

//Java 8
HashSet<Character> vowels = new HashSet<>(Arrays.asList('a', 'e', 'i', 'o', 'u'));
//Java 9+
Set<Character> vowels = Set.of('a', 'e', 'i', 'o', 'u');

for(char c : str) if(vowels.contains(c)) System.out.println(c + "");
Posted by: Guest on April-13-2021
-2

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 "Java"

Java Answers by Framework

Browse Popular Code Answers by Language