Write a Java Program to Delete or Remove Vowels from string (Manual Method)

By | 07.03.2017

Java Program to Delete or Remove Vowels


Write a Java Program to Delete or Remove Vowels from string without inbuilt function ( Manual Method) . For this program, you have to first ask to the user to enter the string and start deleting/removing all the vowels present in the string as shown in the following  program.

In this code snippet, we will learn how to remove all vowels from a string in Java, to implement this logic we are using a loop from 0 to length-1 (here length is the string length) and checking for vowels.

Except of vowel character, other all characters are assigning into another string and that anther string will be the final string that will contain text without any vowels.

We created a method isVowel(), this method will return true if character is vowel else it will return false.

Following Java program removes all the vowels present in the string manually. Here the program is successfully compiled(build) and run (Netbeans) on the windows System and produce output below .Let’s look at the following program :


SOURCE CODE : :


 

import java.io.IOException;
import java.util.Scanner;

public class Remove_Vowels {

   public static void main(String args[]) throws IOException
   {
       Scanner sc = new Scanner(System.in);
       
     System.out.println("----Program to remove vowels from String -----\n ");

     System.out.print("Enter a string: ");
     String str1 = sc.nextLine();

     System.out.print("\nAfter Delete or Remove Vowels :\n Reqd. String is : ");
     String str2 = remove_Vowels(str1);
     System.out.println(str2);
   }

   private static String remove_Vowels(String str)
   {
     String finalString = "";

     for (int i=0; i<str.length(); i++)
     {
       if (!isVowel(Character.toLowerCase(str.charAt(i))))
       {
         finalString += str.charAt(i);
       }
     }
     return finalString;
   }

   private static boolean isVowel(char c) {

     String vowels = "aeiou";
     for (int i=0; i<5; i++)
     {
       if (c == vowels.charAt(i))
         return true;
     }
     return false;
   }
}

OUTPUT : :


----Program to remove vowels from String -----
 
Enter a string: CodezClub

After Delete or Remove Vowels :

 Reqd. String is : CdzClb

 

0 0 votes
Article Rating
Category: Java Programming String Programs Tags:

About Tunde A

My name is Tunde Ajetomobi, a Tech Enthusiast and Growth Hacker. I enjoy creating helpful content that solves problem across different topics. Codezclub is my way of helping young aspiring programmers and students to hone their skills and find solutions on fundamental programming languages.

Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments