Java Program

Object:-Write a Program to remove vowel from given string.

import java.util.Scanner;
public class JavaProgram

{
   public static void main(String args[])
   {
       String str, r;
       Scanner scan = new Scanner(System.in);       
       System.out.print("Enter a String : ");
       str = scan.nextLine();
       System.out.print("Removing Vowels from String [" +str+ "]");
       r = removeVowels(str);  
       System.out.print("Vowels Removed from the Entered String Successfully..!!nNow the String is :n");
       System.out.print(r);
   }
   private static String removeVowels(String s)

   {
     String finalString = "";
     int i;
     for(i=0; i < s.length(); i++)
     {
       if (!isVowel(Character.toLowerCase(s.charAt(i))))
       {
         finalString = finalString + s.charAt(i);
       }
     }
     return finalString;
   }
   private static boolean isVowel(char c)

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

Output

Enter a String : Amit Chaudhary
Removing Vowels from String [" Amit Chaudhary "]
Vowels Removed from the Entered String Successfully..!!

Now the String is :
mt Chdhry
 

Explanation

Java program removes all the vowels present in the string without using library function.








You may also like: