Q:

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

belongs to collection: Java String Solved Programs

0

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 :

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Java String Solved Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Write a Java Program to Sort n Strings in Alphabet... >>
<< Write a Java Program to Swap two strings without u...