Java program to remove vowels from a string using switch case

Hey guys!! Welcome to flower brackets blog. In this post we going to learn java program to remove vowels from a string using switch case.

java program to remove vowels from a string using switch case

Java program to remove vowels from a string using switch case

Here’s the program to remove all vowels from a string in java using switch case,

Also read – remove vowels from string java

public class RemoveVowels
{
   public static boolean checkVowel(char ch)
   {
      switch(ch)
      {
         case 'A':
         case 'E':
         case 'I':
         case 'O':
         case 'U':
         case 'a':
         case 'e':
         case 'i':
         case 'o':
         case 'u':
            return true;
         default:
            return false;
      }
   }
   
   public static void main(String[] args)
   {
      String str1 = "Welcome to Flower Brackets blog!!";
      String str2 = "";
      char vowel;
      System.out.println("Before : " + str1);
      for(int a = 0; a < str1.length(); a++)
      {
         vowel = str1.charAt(a);
         if(!checkVowel(vowel))
         {
            str2 += vowel;
         }
      }
      System.out.println("After : " + str2);
   }
}

Output:

Before : Welcome to Flower Brackets blog!!
After : Wlcm t Flwr Brckts blg!!


Related Posts