Welcome To The World Of Java

This site will teach you the basics of Java. It is not necessary to have any prior programming experience.

Java program to remove vowels from a string.

Somdeb Burman | 10:25:00 AM | 0 comments

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 str1, str2 = "";
   char ch, ch1;
   int i, len;
   System.out.println("Enter the Sentence:");
   str1 = br.readLine();
   len = str1.length();
   for (i = 0; i < len; i++) {
    ch = str1.charAt(i);
    ch1 = Character.toLowerCase(ch);
    switch (ch1) {
     case 'a':
     case 'e':
     case 'i':
     case 'o':
     case 'u':
      break;
     default:
      str2 = str2 + ch;
    }                           //switch ends
   }                            //for ends
   System.out.println("Modified string without vowels:" + str2);
  }                            //method ends
}

Output:
Enter the Sentence:
umesh kumar kushwaha
Modified string without vowels:msh kmr kshwh

Java Resources are available for Download from below

Category: , , , ,

0 comments