Java program to remove vowels from a string

Java program to remove vowels from a string

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

Java program to remove vowels from a string

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 remove vowels from string : " + str1);
for(int a = 0; a < str1.length(); a++)
{
vowel = str1.charAt(a);
if(!checkVowel(vowel))
{
str2 += vowel;
}
}
System.out.println("After remove vowels from string : " + str2);
}
}

Output:

Before remove vowels from string : Welcome to Flower Brackets blog!!
After remove vowels from string : Wlcm t Flwr Brckts blg!!


Related Posts