Java program to remove vowels from a string using switch case

Let’s 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

Remove vowels from string java is the most common java interview question.

Also read – classes and objects in java

Did you know to remove vowels using switch case. Here’s the program to remove vowels from a string in java using switch case,

// remove vowels from string
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class RemoveVowels
{
   public static void main(String[] args) throws IOException 
   {
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      String strFirst, str = "";
      char ch, chCase;
      int a, len;
      System.out.println("Please enter a sentence : ");
      strFirst = br.readLine();
      len = strFirst.length();
      for(a = 0; a < len; a++) 
      {
         ch = strFirst.charAt(a);
         chCase = Character.toLowerCase(ch);
         switch(chCase) 
         {
            case 'a':
            case 'e':
            case 'i':
            case 'o':
            case 'u':
               break;
            default:
               str = str + ch;
         }
      }
      System.out.println("String without vowels : " + str);
   }
}




Output:

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

Please enter a sentence : flower brackets
String without vowels : flwr brckts