Thursday, March 17, 2011

BlueJ Program On Removing Vowels From A String

import java.io.*;
class StringVowel
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String str1,str2="";
char ch;
int i,len;
public void show() throws Exception
{
System.out.println("Enter the Sentence:");
str1=br.readLine();
len=str1.length();
for(i=0;i < len;i++)
{
ch=str1.charAt(i);
switch(ch)
 {
 case 'a':
case 'A':
case 'e':
case 'E':
case 'i':
case 'I':
case 'o':
case 'O':
 case 'u':
case 'U':
break;
default: str2=str2+ch;
}
 }
System.out.println("Modified string without vowels:"+str2);
 }
public static void main(String args[]) throws Exception
{
StringVowel ob=new StringVowel ();
ob.show();
}
}

Related Post:  BlueJ Programs on String/Sentence


Technical analysis of this program



The entered string including vowels (may not contain vowel also) is stored in an object ‘str1’ of string class. Another string class object is kept in this program to hold the modified string values-without vowels. Each character is accessed and using ‘switch’, the character is checked for vowel or not. If the character is not a vowel then it is concatenated with the second string object. The same process is repeated for all characters of the entered string.

2 comments:

Subscribe via email

Enter your email address:

Delivered by FeedBurner